GatewayESP8266MQTTClient in Development Branch



  • Hi,

    I am starting to do some testing with the GatewayESP8266MQTTClient in the Dev branch. How do we define our own nodeid's. In the past I would do it via begin() in void setup{}. Do we now put begin() in the presentation function?

    Mike



  • I'm trying the ENC28J60 branch and am also wondering the same thing. The setup and main functions are empty?


  • Admin

    @Mike-Cayouette

    #define MY_NODE_ID xxx

    But for the gateway this is not needed as they always get id=0

    @gmccarthy
    Unless you want to attach sensors to the gateway itself, you can leave presentation() and setup() empty.



  • @hek Thank you. I should have mentioned I have the gateway working but I was wondering how to define the node id in the clients. In any case, I was coming back here to say I had figured it out.

    I have a temp sensor communicating with the gateway.

    Mike



  • @hek Gateway and sensor node never get communicated even after configuring manual ID. Here is arduino debug

    Starting...
    find parent
    send: 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc:
    find parent
    send: 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc:
    find parent
    send: 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc:
    

    Here is the ESP8266 12E gateway debug

    0;0;3;0;9;Starting...
    scandone
    f 0, ....scandone
    state: 0 -> 2 (b0)
    .state: 2 -> 3 (0)
    state: 3 -> 5 (10)
    add 0
    aid 1
    cnt 
    
    connected with Ahmed, channel 1
    ip:192.168.0.31,mask:255.255.255.0,gw:192.168.0.1
    .IP: 192.168.0.31
    0;0;3;0;9;gateway started, id=0, parent=0, distance=0
    0;0;3;0;9;Attempting MQTT connection...
    0;0;3;0;9;MQTT connected
    

  • Hardware Contributor

    There seems to be a bug in incomingMQTT:
    replace
    for (str = strtok_r(topic, "/", &p); str && i < 5;
    with
    for (str = strtok_r(topic, "/", &p); str && i <= 5;

    -> http://forum.mysensors.org/topic/1870/esp8266-wifi-gateway-port-for-mysensors/138


  • Admin

    Ok, created a PR on this.

    https://github.com/mysensors/Arduino/pull/229

    Will just let it run through Jenkins before merging.


  • Hardware Contributor

    There may be other problems in the code. I switched to ethernet gateway and wrote my own controller in node-red (wip).



  • @FotoFieber I switched to ethernet gateway and wrote my own controller in node-red

    I am attempting the same . For some reason though I cannot get the mysensors ESP8266Gateway to receive data from node-red. I configured a TCP node in node-red with the gateways IP on port 5003. When I connect the serial monitor I can see the client connection established, but when I send data from node-red I get nothing. I am able to telenet to the gateway and in the serial monitor I see the messages I type so I know the gateway can receive, but it does not receive from node-red. How did you get node-red and the gateway to exchange messages?

    Thank you,

    Mike


  • Hardware Contributor

    @Mike-Cayouette
    What kind of tcp node do you use?

    I use a tcp request node and inject a blank on startup to get the connection opened.



  • Hello,

    This reply is related to another topic http://forum.mysensors.org/topic/2378/how-can-i-set-the-payload-for-mqtt-v1-6 where I wasn't able to send my buffer from my mqtt gateway to another sensor node. After spending all day today debugging the issue, I was able to find two bugs and to send the buffer correctly.

    This is the topic which I subscribe to

    #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygatewayin"
    

    This is how I send my mqtt pattern using MQTTlens or Mosquitto to be published to the gateway. My message contains 1 or 0 to turn ON or OFF a relay in my sensor node with id 4, child id 19, set, no ack, V_LIGHT

    mygatewayin/4/19/1/0/2
    

    The first problem which I faced is that my mqtt buffer wasn't evaluated in the callback function incomingMQTT() found in MyGatewayTransportMQTTClient.cpp

    After checking the case switch I found out that the rest of the case switches doesn't continue because the code returns due to the following line

    if (strcmp_P(str, MY_MQTT_SUBSCRIBE_TOPIC_PREFIX) != 0)
    {
        return;
    }
    

    According to http://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html#gad34d5b7d040fcb97939e939f19d88a5f

    The strcmp_PF() function returns an integer less than, equal to, or greater than zero if s1 is found, respectively, to be less than, to match, or be greater than s2. The contents of RAMPZ SFR are undefined when the function returns

    Actually I haven't used this function before but according to description it will return 0 if they are identical, so using != shall be right, but actually it was solved when I replaced it with == instead of !=

    Finally I was able to evaluate the buffer and the case switches continued.

    But Also this didn't solve the problem and the buffer wasn't sent to the sensor node id 4

    After lots of printing functions for debugging I found that in serial monitoring, the following is printed

    send: 0-0-0-4 s=19,c=1,t=2,pt=0,l=1,sg=0,st=fail:1
    

    While when I use Serial gateway which is working well till now, the following is printed instead

    send: 0-0-4-4 s=19,c=1,t=2,pt=0,l=1,sg=0,st=ok:1
    

    Thus I found that the difference is in 0-0-X-4.

    Searching further in the code, I found that the debug function for this line is used in MyTransport.cpp in function transportSendWrite(uint8_t to, MyMessage &message)

    debug(PSTR("send: %d-%d-%d-%d s=%d,c=%d,t=%d,pt=%d,l=%d,sg=%d,st=%s:%s\n"),
    			message.sender,message.last, to, message.destination, message.sensor, mGetCommand(message), message.type,
    			mGetPayloadType(message), mGetLength(message), mGetSigned(message), to==BROADCAST_ADDRESS ? "bc" : (ok ? "ok":"fail"), message.getString(_convBuf));
    

    So the difference here is that the variable to is set as 0 in case of mqttgateway, while it is set as 4 correctly using Serial gateway.

    So finally this is what I have reached.

    In MyTransport.cpp in function boolean transportSendRoute(MyMessage &message)

    #if !defined(MY_REPEATER_FEATURE)
        // None repeating node... We can only send to our parent\\
        ok = transportSendWrite(_nc.parentNodeId, message);
    #endif
    

    The above is called because MY_REPEATER_FEATURE is not defined, thus the mqttgateway sends always 0 instead of the required node id.

    I tried to define MY_REPEATER_FEATURE but I found big memory size and the software was crazy.
    Also in MySensor.h it is not mentioned to be defined

    #if defined(MY_GATEWAY_MQTT_CLIENT)
    ... some code ...
    ... some code ...
    #elif defined(MY_GATEWAY_FEATURE)
    ... some code ...
    	#if defined(MY_RADIO_FEATURE)
    		// We assume that a gateway having a radio also should act as repeater
    		#define MY_REPEATER_FEATURE
    	#endif
    

    What I did now as a workaround because it is 2:40 AM here and I need to sleep 😄 Is the following

    In MyTransport.cpp

    	#if !defined(MY_REPEATER_FEATURE)
    		#if defined(MY_GATEWAY_MQTT_CLIENT)
    			ok = transportSendWrite(message.destination, message);
    		#else
    		// None repeating node... We can only send to our parent
    		ok = transportSendWrite(_nc.parentNodeId, message);
    		#endif
    	#else
    

    Please check whether this will solve the problem or not. Please correct me if I was wrong. It's my first time to look around in the library today.

    Thanks.


  • Admin

    @ahmedadelhosni said:

    MY_REPEATER_FEATURE

    Good catch, I'll do some tests and check in something.



  • @hek Thanks. I am sure you will come up with a better general solution 😄


Log in to reply
 

Suggested Topics

  • 1
  • 10
  • 5
  • 3
  • 1
  • 6

12
Online

11.4k
Users

11.1k
Topics

112.7k
Posts