ESP-8266 gateway with sensor can't communicate with controller



  • hi everybody,

    I've read a lot of topics but can't seem to find out what i'm doing wrong.
    I've a wemos D1 mini with a switch connected to it and i want to send the state of this switch to Home Assistant
    The following code is running on my d1:

    #include <EEPROM.h>
    #include <SPI.h>
    #include <Bounce2.h>
    
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    // Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h
    #define MY_BAUD_RATE 9600
    
    #define MY_GATEWAY_ESP8266
    
    #define MY_ESP8266_SSID "xxxxxxx"
    #define MY_ESP8266_PASSWORD "xxxxxxx"
    
    // If using static ip you need to define Gateway and Subnet address as well
    #define MY_IP_ADDRESS 192,168,0,9
    #define MY_IP_GATEWAY_ADDRESS 192,168,0,1
    #define MY_IP_SUBNET_ADDRESS 255,255,255,0
    
    // The port to keep open on node server mode 
    #define MY_PORT 5003      
    
    // How many clients should be able to connect to this gateway (default 1)
    #define MY_GATEWAY_MAX_CLIENTS 2
    
    
    #define CHILD_ID 1
    #define BUTTON_PIN  0  // Arduino Digital I/O pin for button/reed switch
    
    
    #include <ESP8266WiFi.h>
    #include <MySensors.h>
    
    Bounce debouncer = Bounce(); 
    int oldValue=-1;
    bool initialValueSent = false;
    
    MyMessage msg(CHILD_ID,V_STATUS);
    
    void setup() { 
      pinMode(BUTTON_PIN,INPUT_PULLUP);
      // Activate internal pull-up
      //digitalWrite(BUTTON_PIN,HIGH);
      // After setting up the button, setup debouncer
      debouncer.attach(BUTTON_PIN);
      debouncer.interval(5);
    }
    
    void presentation() {
      // Present locally attached sensors here    
      Serial.println("Presentation:");
      
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Switch", "1.1");
      present(CHILD_ID, S_BINARY); 
    }
    
    
    void loop() {
      debouncer.update();
      // Get the update value
       int value = debouncer.read();
      if (value != oldValue) {
         // Send in the new value
         Serial.println(value);
         send(msg.set(value==HIGH ? 1 : 0));
         oldValue = value;
      }
      // Send locally attached sensors data here
    }
    
    void receive(const MyMessage &message) {
      if (message.isAck()) {
         Serial.println("This is an ack from gateway");
      }
      Serial.println("something was received: "+ message.type);
    }
    
    

    and got follwing output

    0;255;3;0;9;Starting gateway (R-NGE-, 2.0.0)
    scandone
    f 0, scandone
    state: 0 -> 2 (b0)
    state: 2 -> 3 (0)
    state: 3 -> 5 (10)
    add 0
    aid 3
    cnt 
    
    connected with telenet-CED24D5, channel 11
    ip:192.168.0.9,mask:255.255.255.0,gw:192.168.0.1
    .IP: 192.168.0.9
    0;255;3;0;9;No registration required
    0;255;3;0;9;Init complete, id=0, parent=0, distance=0, registration=1
    1
    pm open,type:2 0
    

    and in home assistant i get following in the debug:

    16-12-31 11:45:08 mysensors.mysensors: Trying to connect to ('192.168.0.9', 5003)
    16-12-31 11:45:08 mysensors.mysensors: Connected to ('192.168.0.9', 5003)
    16-12-31 11:45:09 netdisco.service: Scanning
    16-12-31 11:45:09 mysensors.mysensors: Received 0;255;3;0;14;Gateway startup complete.
    0;255;3;0;11;Switch
    0;255;3;0;12;1.1
    0;1;0;0;3;
    
    16-12-31 11:45:09 mysensors.mysensors: Node 0 is unknown
    16-12-31 11:45:09 mysensors.mysensors: Requesting new presentation for node 0
    16-12-31 11:45:09 mysensors.mysensors: Node 0 is unknown
    16-12-31 11:45:09 mysensors.mysensors: Requesting new presentation for node 0
    16-12-31 11:45:09 mysensors.mysensors: Node 0 is unknown
    16-12-31 11:45:09 mysensors.mysensors: Requesting new presentation for node 0
    16-12-31 11:45:09 mysensors.mysensors: Node 0 is unknown, will not add child 1.
    16-12-31 11:45:09 mysensors.mysensors: Sending 0;255;3;0;19;
    
    16-12-31 11:45:09 mysensors.mysensors: Sending 0;255;3;0;19;
    
    16-12-31 11:45:09 mysensors.mysensors: Sending 0;255;3;0;19;
    

    can someone help me getting this working


  • Mod

    @Senne-Vande-Sompele try upgrading to MySensors 2.1 (which was relesed yesterday). 2.0 has a problem that causes the receive function to not be called on nodes that are gateways.


  • Plugin Developer

    @Senne-Vande-Sompele

    Mysensors 2.0 has a bug that leads to gateways without radio to not present themselves, which is why node 0 (gateway) is unknown in your log. This is fixed in mysensors 2.1.



  • I've upgraded and everything works now thank you very much


  • Mod

    Great work @Senne-Vande-Sompele, thanks for reporting back!


Log in to reply
 

521
Online

6.9k
Users

7.8k
Topics

82.9k
Posts

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.