B4R Question Mqtt Broker on ESP8266 (IDE B4R not working) (Arduino IDE ok)

XorAndOr

Active Member
Licensed User
Longtime User
Hi everyone
I've been trying to get it to work for days a mqtt broker on an esp8266 with #if C code and calling it with RunNative in B4R.
If I program the esp8266 with Arduino code everything works. I tried three different brokers with C code for arduino in B4R
I also created a b4r library b4xlib which I included both the connection station and the broker.
But after programming with B4R it doesn't work.
Log client B4J
B4X:
(ConnectException) java.net.ConnectException: Connection timed out: no further information
What I don't understand is why if I program it with arduino everything works,
while with B4R with arduino code in C and RunNative it doesn't work.
p.s. (I know I should be using Raspberry for this)

I found 2 forum threads about it
https://www.b4x.com/android/forum/threads/mqtt-broker-on-esp8266.89578/#content

https://www.b4x.com/android/forum/threads/porting-arduino-code-to-b4r.92985/#content

Thank you for help

I attach the files of the tests I did
 

Attachments

  • B4RBroker.zip
    2.2 KB · Views: 176
  • ClientMqtt.zip
    3.4 KB · Views: 168
  • ArduinoCode.zip
    1 KB · Views: 183

XorAndOr

Active Member
Licensed User
Longtime User
Yes, it works!!
Thank you very much @candide for your interest and help.
I tried the 2 B4R projects, (test_rsMQTTBroker_basic) it works, now the client connects.
I have to do more tests to send the commands, but it's already something great that you made it work thank you very much.
The other project (test_rsMQTTBroker) connects to the router and then the esp8266 goes into error and restarts.
p.s. I had already tried this library but with RunNative and it didn't work.
thanks
 
Upvote 0

candide

Active Member
Licensed User
after more tests done, this is the new version with some fix, i had issues with "std::string" strings.

now we have only one callback in case of connection lost, to make an action to recover the link and all others events are now only traces .
you can add or remove traces.

i tested transfer of message, it is working with simple topic ( i don't know if we have a limitation on the number of chars or on special chars)
 

Attachments

  • rsMQTTBroker_v2.zip
    16.9 KB · Views: 172
Upvote 0

XorAndOr

Active Member
Licensed User
Longtime User
now we have only one callback in case of connection lost, to make an action to recover the link and all others events are now only traces .
you can add or remove traces.
hi candide,
I would like to ask you how do I add the event in B4R
B4X:
Sub OnPublish(ClientID As ULong, Topic() As Byte, Payload() As Byte)
    Log("New Publish, ClientID: ",ClientID," Topic: ",Topic, " Payload: ", Payload)
End Sub
or replace it instead of OnLostConnection
I would like to make the esp8266 do some operations when a command arrives, as well as send a msg to the client
Thank you
 
Last edited:
Upvote 0
Top