Sayfayı Yazdır | Pencereyi Kapat

MQTT

Nereden Yazdırıldığı: Clomosy | Forum
Kategori: Genel Programlama
Forum Adı: Genel İşlemler
Forum Tanımlaması: TRObject dili ile programlama yaparken karşılaşılan genel işlemler
URL: https://forum.clomosy.com.tr/forum_posts.asp?TID=836
Tarih: 06 Ocak 2025 Saat 14:05
Program Versiyonu: Web Wiz Forums 12.07 - https://www.webwizforums.com


Konu: MQTT
Mesajı Yazan: Habip
Konu: MQTT
Mesaj Tarihi: 07 Ağustos 2024 Saat 17:31
var 
  SpyFallForm:TclForm
  JoinRoomBtn,CopyBtn:TClProButton;
  JoinRoomEdt:TclProEdit;
  OneSpy,DoubleSpy:TCLRadioButton;
  OneSpyImage,DoubleSpyImage:TClProImage;
  GameTimeCombo:TCLComboBox;
  PlayersPanel,panelPlayer:TclProPanel;
  userName:TClProLabel;
  playerStatusImage:TClProImage;
  TestHorz : TClHorzScrollBox;
  RoomId:TClProLabel;
  roomIDStr:String;
  ModMQTT,PlayerMQTT:TclMQTT;
  JoinTimer:TCLTimer;
void PlayerMQTTStatusChanged; 
   if (PlayerMQTT.Connected )  
   {  
      ShowMessage(Clomosy.AppUserDisplayName+' Bağlandı');
   } 
   Else
   { 
      ShowMessage(Clomosy.AppUserDisplayName+' Bağlanamadı');
   } 
}
void JoinTimerEnabled
{
  if(JoinTimer.Interval==1)
  {
    JoinTimer.Interval=1000;
  }
  else
  {
    PlayerMQTT.Send('Habip Bağlandı');
    JoinTimer.Enabled=false;
  }
}
void ModMQTTPublishReceived; 
 {
  if(ModMQTT.ReceivedAlright)  
  { 
  /*
    if(ModMQTT.ReceivedMessage=='Habip Bağlandı')
    {
      userName=SpyFallForm.AddNewProLabel(PlayersPanel, 'userName', Clomosy.AppUserDisplayName);
      clComponent.SetupComponent(userName,'{
        "Align":"Center",
        "Width":150,
        "Height":40,
        "TextColor":"#323036",
        "TextSize":20,
        "TextVerticalAlign":"Center",
        "TextBold":"Yes",
        "MarginLeft":150
      }');
    }
  */
  } 
 } 
void JoinRoomBtnOnClick
{
  PlayerMQTT.Channel=JoinRoomEdt.text;
  PlayerMQTT.Connect;
  JoinTimer.Enabled=true;
}
void setModeratorForm
{
  SpyFallForm=TclForm.Create(Self);
  SpyFallForm.SetFormColor('#323036', '', clGNone);
  
  
  OneSpy=SpyFallForm.AddNewRadioButton(SpyFallForm, 'OneSpy', '');
  OneSpy.Margins.Top=SpyFallForm.clHeight*4/10;
  OneSpy.Margins.Right=SpyFallForm.clWidth*9/100;
  OneSpy.ischecked=true;
  
  DoubleSpy=SpyFallForm.AddNewRadioButton(SpyFallForm, 'DoubleSpy', '');
  DoubleSpy.Margins.Top=SpyFallForm.clHeight*4/10;
  DoubleSpy.Margins.Left=SpyFallForm.clWidth*23/100;
  
  OneSpyImage = SpyFallForm.AddNewProImage(SpyFallForm,'OneSpyImage');
  OneSpyImage.Margins.Top=SpyFallForm.clHeight*4/10;
  OneSpyImage.Margins.Right=SpyFallForm.clWidth*16/100;
  clComponent.SetupComponent(OneSpyImage,'{
    "Width":27,
    "Height":27,
    "ImgUrl":"https://i.imgur.com/hQyynu1.png",
    "ImgFit":"yes"
  }');
  
  DoubleSpyImage = SpyFallForm.AddNewProImage(SpyFallForm,'DoubleSpyImage');
  DoubleSpyImage.Margins.Top=SpyFallForm.clHeight*4/10;
  DoubleSpyImage.Margins.Left=SpyFallForm.clWidth*20/100;
  clComponent.SetupComponent(DoubleSpyImage,'{
    "Width":50,
    "Height":50,
    "ImgUrl":"https://i.imgur.com/qchaHr2.png",
    "ImgFit":"yes"
  }');
  
  GameTimeCombo=SpyFallForm.AddNewComboBox(SpyFallForm, 'GameTimeCombo');
  GameTimeCombo.Align=alCenter;
  GameTimeCombo.Margins.Top=SpyFallForm.clHeight*25/100;
  GameTimeCombo.AddItem('6:00','01');
  GameTimeCombo.AddItem('7:00','02');
  GameTimeCombo.AddItem('8:00','03');
  GameTimeCombo.AddItem('9:00','04');
  GameTimeCombo.AddItem('10:00','05');
  
  PlayersPanel=SpyFallForm.AddNewProPanel(SpyFallForm, 'PlayersPanel');
  PlayersPanel.margins.bottom=SpyFallForm.clHeight*4/10;
  clComponent.SetupComponent(PlayersPanel,'{
    "Width":370,
    "Height":350,
    "RoundHeight":10,
    "RoundWidth":10,
    "BorderWidth":5,
    "BorderColor":"#FFFFFF",
    "BackgroundColor":"#323036"
  }');

  TestHorz = SpyFallForm.AddNewHorzScrollBox(PlayersPanel,'TestHorz');
  
  roomIDStr=Clomosy.AppUserGUID;
  
  RoomId=SpyFallForm.AddNewProLabel(SpyFallForm, 'RoomId', 'Oda ID: '+roomIDStr);
  RoomId.Margins.Top=SpyFallForm.clHeight*5/10;
  clComponent.SetupComponent(RoomId,'{
    "Width":200,
    "Height":40,
    "TextColor":"#DAC0A3",
    "TextSize":20,
    "TextVerticalAlign":"Center",
    "TextBold":"Yes"
  }');
  
  CopyBtn=SpyFallForm.AddNewProButton(SpyFallForm, 'CopyBtn', '');
  CopyBtn.Margins.Top=SpyFallForm.clHeight*5/10;
  CopyBtn.Margins.Left=RoomId.Width;
  clComponent.SetupComponent(CopyBtn,'{
    "Width":20,
    "Height":20,
    "ImgUrl":"https://i.imgur.com/DU8Bb0p.png",
    "BackgroundColor":"#DAC0A3",
    "ImgFit":"yes"
  }');
  
  ModMQTT = SpyFallForm.AddNewMQTTConnection(PlayersPanel,'ModMQTT');
  SpyFallForm.AddNewEvent(ModMQTT,tbeOnMQTTPublishReceived,'ModMQTTPublishReceived');
  ModMQTT.Channel=Clomosy.AppUserGUID;
  ModMQTT.Connect;
  
  SpyFallForm.Run;
}
void setPlayerForm
{
  SpyFallForm=TclForm.Create(Self);
  SpyFallForm.SetFormColor('#323036', '', clGNone); 
  
  JoinRoomBtn=SpyFallForm.AddNewProButton(SpyFallForm, 'JoinRoomBtn', 'Odaya Katıl');
  JoinRoomBtn.Height=50;
  JoinRoomBtn.Width=150;
  JoinRoomBtn.Margins.Top=SpyFallForm.clHeight*4/10
  clComponent.SetupComponent(JoinRoomBtn,'{
    "Width":150,
    "Height":50,
    "RoundHeight":10,
    "RoundWidth":10,
    "BorderColor":"#FFFFFF",
    "BorderWidth":2,
    "FontColor":"#FFFFFF",
    "BackgroundColor":"#DAC0A3"
  }');
  
  JoinRoomEdt=SpyFallForm.AddNewProEdit(SpyFallForm, 'JoinRoomEdt', 'Oda ID giriniz...');
  JoinRoomEdt.Margins.Top=SpyFallForm.clHeight*2/10
  clComponent.SetupComponent(JoinRoomEdt,'{
    "Width":180,
    "Height":30,
    "RoundHeight":10,
    "RoundWidth":2,
    "BorderColor":"#FFFFFF",
    "BorderWidth":2
  }');
  
  panelPlayer=SpyFallForm.AddNewProPanel(SpyFallForm, 'panelPlayer');
  panelPlayer.margins.bottom=SpyFallForm.clHeight*4/10;
  clComponent.SetupComponent(panelPlayer,'{
    "Width":370,
    "Height":50,
    "RoundHeight":10,
    "RoundWidth":10,
    "BorderWidth":5,
    "BorderColor":"#FFFFFF",
    "BackgroundColor":"#DAC0A3"
  }');
  
  userName=SpyFallForm.AddNewProLabel(panelPlayer, 'userName', Clomosy.AppUserDisplayName);
  clComponent.SetupComponent(userName,'{
    "Align":"Center",
    "Width":150,
    "Height":40,
    "TextColor":"#323036",
    "TextSize":20,
    "TextVerticalAlign":"Center",
    "TextBold":"Yes",
    "MarginLeft":150
  }');
  
  playerStatusImage=SpyFallForm.AddNewProImage(panelPlayer, 'playerStatusImage');
  clComponent.SetupComponent(playerStatusImage,'{
    "Align":"Right",
    "Width":27,
    "Height":27,
    "ImgUrl":"https://i.imgur.com/xAERIXD.png",
    "ImgFit":"yes",
    "MarginRight":50
  }');
  
  PlayerMQTT=SpyFallForm.AddNewMQTTConnection(SpyFallForm,'PlayerMQTT');
  SpyFallForm.AddNewEvent(PlayerMQTT,tbeOnMQTTStatusChanged,'PlayerMQTTStatusChanged');
  
  JoinRoomBtn.OnClick='JoinRoomBtnOnClick';
  
  JoinTimer=SpyFallForm.AddNewTimer(SpyFallForm,'JoinTimer',1);
  JoinTimer.OnTimer='JoinTimerEnabled';
  
  SpyFallForm.Run;
}

{
  if(Clomosy.AppUserProfile == 1)
  {
    setModeratorForm;
  }
  else
  {
    setPlayerForm;
  }
}




Cevaplar:
Mesajı Yazan: oguz22
Mesaj Tarihi: 07 Ağustos 2024 Saat 17:49
Merhabalar kodu denediğim zaman bir hata göremedim ama.


Mesajı Yazan: Habip
Mesaj Tarihi: 07 Ağustos 2024 Saat 17:53
var 
  SpyFallGiris:TclForm
  CreateRoomBtn,JoinRoomBtn:TClProButton;
  girisImage:TClProImage;
  girisTimer1,girisTimer2:TCLTimer;
void goToSpyFall
{
  Clomosy.RunUnit('uSpyFallGiris');
}
void GirisEkrani
{
  if(girisTimer1.Interval==1)
  {
    girisTimer1.Interval=1000;
  }
  else
  {
    girisTimer1.enabled=false;
    girisTimer2.enabled=true;
  }
}
void Kucult
{
  if(girisImage.Width>100)
  {
    girisImage.Width=girisImage.Width-5;
    girisImage.Height=girisImage.Height-6;
    girisImage.margins.Bottom=girisImage.margins.Bottom+6
  }
  else
  {
    girisTimer2.enabled=false;
    CreateRoomBtn.visible=true;
    JoinRoomBtn.visible=true;
  }
}
void CreateRoomBtnOnClick
{
  Clomosy.AppUserProfile=1
  goToSpyFall;
}
void JoinRoomBtnOnClick
{
  Clomosy.AppUserProfile=0;
  goToSpyFall;
}
{
  SpyFallGiris=TclForm.Create(Self);
  SpyFallGiris.SetFormColor('#323036', '', clGNone); 
  
  CreateRoomBtn=SpyFallGiris.AddNewProButton(SpyFallGiris, 'CreateRoomBtn', 'Oda Oluştur');
  CreateRoomBtn.Height=50;
  CreateRoomBtn.Width=150;
  CreateRoomBtn.Margins.Bottom=SpyFallGiris.clHeight*1/10
  clComponent.SetupComponent(CreateRoomBtn,'{
    "Width":150,
    "Height":50,
    "RoundHeight":10,
    "RoundWidth":10,
    "BorderColor":"#FFFFFF",
    "BorderWidth":2,
    "FontColor":"#FFFFFF",
    "BackgroundColor":"#DAC0A3"
  }');
  CreateRoomBtn.visible=false;
  
  JoinRoomBtn=SpyFallGiris.AddNewProButton(SpyFallGiris, 'JoinRoomBtn', 'Odaya Katıl');
  JoinRoomBtn.Height=50;
  JoinRoomBtn.Width=150;
  JoinRoomBtn.Margins.Top=SpyFallGiris.clHeight*1/10
  clComponent.SetupComponent(JoinRoomBtn,'{
    "Width":150,
    "Height":50,
    "RoundHeight":10,
    "RoundWidth":10,
    "BorderColor":"#FFFFFF",
    "BorderWidth":2,
    "FontColor":"#FFFFFF",
    "BackgroundColor":"#DAC0A3"
  }');
  JoinRoomBtn.visible=false;
  
  girisImage=SpyFallGiris.AddNewProImage(SpyFallGiris,'girisImage');
  clComponent.SetupComponent(girisImage,'{
    "Align":"Center",
    "Width":400,
    "Height":517,
    "ImgUrl":" https://i.imgur.com/AVJKUct.png" rel="nofollow - https://i.imgur.com/AVJKUct.png" ,
    "ImgFit":"yes"
  }');
  
  girisTimer1=SpyFallGiris.AddNewTimer(SpyFallGiris,'girisTimer1',1);
  girisTimer1.OnTimer='GirisEkrani';
  girisTimer1.enabled=true;
  
  girisTimer2=SpyFallGiris.AddNewTimer(SpyFallGiris,'girisTimer2',1);
  girisTimer2.OnTimer='Kucult';
  
  CreateRoomBtn.OnClick='CreateRoomBtnOnClick';
  JoinRoomBtn.OnClick='JoinRoomBtnOnClick';
  
  SpyFallGiris.Run;
}







Ana Kod olarak bu kodu çalıştırıp ilk attığım kodu unit olarak çalıştırın lütfen. İki farklı cihazda, birinde 'oda oluştur', diğerinde 'odaya katıl' butonuna basıp 'oda oluştur' yaptığınız cihazda gözüken ID'yi 'odaya katıl' sayfasında ID kısmına yazıp katıl butonuna basınız lütfen  


Mesajı Yazan: Developer
Mesaj Tarihi: 03 Eylül 2024 Saat 15:36
Merhaba Habib,
Mqtt ile ilgili aşağıdaki linki inceler misin:
https://www.docs.clomosy.com/index.php/MQTT" rel="nofollow - https://www.docs.clomosy.com/index.php/MQTT




Sayfayı Yazdır | Pencereyi Kapat

Forum Software by Web Wiz Forums® version 12.07 - https://www.webwizforums.com
Copyright ©2001-2024 Web Wiz Ltd. - https://www.webwiz.net