B4R Question How to connect with MQTT using ESP8266

AndroidMadhu

Active Member
Licensed User
Hello,
I want to connect CloudMQTT server using ESP8266.
Could you please provide me any tutorials or example please.

Thanks
 

AndroidMadhu

Active Member
Licensed User
I am able to connect to WiFi router successfully. But not able to understand the first parameter of the below details
B4X:
mymqtt.Initialize2

What will be value for Stream and ClientID at Initialize2.

Please advice
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
What will be value for Stream
If you see the examples, you have to declare client as WiFiSocken and use client.Stream as first parameter.

B4X:
Sub Process_Globals
    Private client As WiFiSocket
End Sub


 
Upvote 0

AndroidMadhu

Active Member
Licensed User
Sub Process_Globals Private client As WiFiSocket End Sub
Thank you All... I am able to publish the message at CloudMQTT.
The only issue is I am able to put any counter value at the Publish function.
B4X:
mqttclient.Publish("esp","thank you for your m-ESP")
How Can I put a counter after ESP string?
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Try something like:

B4X:
mqttclient.Publish("esp","thank you for your m-ESP number: " & counterValue)
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Sorry, I was thinking in B4A.
If I'm not wrong, try this:

B4X:
Private Sub mtimer_Tick
  counter = counter+1
  Dim b() As Byte = "thank you for your m-ESP: " & counter
  mqttclient.Publish("esp",b)
End Sub

Please, use [code]...paste your code here...[/code] to show your code
 
Upvote 0

AndroidMadhu

Active Member
Licensed User
Super....Its Working.....
If I will use GSM SIM 800 instead of WiFi [ESP8266] to connect to CloudMQTT, then should I declare the client same as before ? like below
B4X:
Private client As WiFiSocket
Please advice.....
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…