Connecting first node to new gateway - what am I missing?



  • I'm just getting into MySensors. I've purchased a variety of parts and played around with connecting sensors to the arduinos on a breadboard. I've had an openHAB server running for various things in my home for over a year, and have been using MQTT for some of the things connected to it.

    I just got a NodeMcu Lua ESP8266 0.9 board so that I can make a wifi gateway that connects to my MQTT broker. I followed the steps on the Building a WiFi Gateway using ESP8266 page. I got MySensors 2.0 installed with the Arduino IDE on my windows 8.1 machine. I believe I was able to successfully the GatewayESP8266MQTTClient sketch that comes with the MySensors library.

    It successfully connects to MQTT.

    0;255;3;0;9;Starting gateway (RNNGE-, 2.0.0)
    0;255;3;0;9;TSM:INIT
    0;255;3;0;9;TSM:RADIO:OK
    0;255;3;0;9;TSM:GW MODE
    scandone
    state: 0 -> 2 (b0)
    state: 2 -> 3 (0)
    state: 3 -> 5 (10)
    add 0
    aid 8
    cnt 
    
    connected with MY-WIFI-SSID, channel 11
    dhcp client start...
    0;255;3;0;9;TSM:READY
    f r0, scandone
    .ip:192.168.1.175,mask:255.255.255.0,gw:192.168.1.1
    .IP: 192.168.1.175
    0;255;3;0;9;No registration required
    0;255;3;0;9;Init complete, id=0, parent=0, distance=0, registration=1
    IP: 192.168.1.175
    0;255;3;0;9;Attempting MQTT connection...
    0;255;3;0;9;MQTT connected
    pm open,type:2 0
    0;255;3;0;9;TSP:SANCHK:OK
    0;255;3;0;9;TSP:SANCHK:OK
    0;255;3;0;9;TSP:SANCHK:OK
    0;255;3;0;9;TSP:SANCHK:OK
    

    The line that shows up 4 times at the end there continues to repeat as long as I leave the gateway running.

    The first sensor I'm trying to make is a simple Dallas temperature sensor on an Arduino Pro Mini 5v with no other sensors attached on the node. I've been able to get successful readings through the serial output in both codebender and the Arduino IDE. Since I'm using MySensors 2.0 in Arduino IDE and that version doesn't work in codebender, I'm trying to get this node to also work in Arduino IDE. From what I can tell, the sketch on the Temperature Sensor page is for the older MySensors library and it causes errors in Arduino IDE with MySensors 2.0. I didn't see any premade sketch for just a DallasTemperatureSensor, so I've attempted to combine a working temprature sensor sketch with the MySensors calls from another sketch. Here's what I came up with:

    /*
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     *
      */
    
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    // Include the libraries we need
    #include <OneWire.h>
    #include <DallasTemperature.h>
    #include <MySensors.h>
    
    
    #define CHILD_ID 0
    
    MyMessage msg(CHILD_ID, V_TEMP);  
    unsigned long SLEEP_TIME = 10000; // Sleep time between reads (in milliseconds)
    
    
    
    // Data wire is plugged into port 2 on the Arduino
    #define ONE_WIRE_BUS 3
    
    // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
    OneWire oneWire(ONE_WIRE_BUS);
    
    // Pass our oneWire reference to Dallas Temperature. 
    DallasTemperature sensors(&oneWire);
    
    // arrays to hold device address
    DeviceAddress insideThermometer;
    
    
    
    void presentation()  {
      sendSketchInfo("My Custom Temp Sensor", "1.0");
      present(CHILD_ID, S_TEMP);  
    }
    
    
    /*
     * Setup function. Here we do the basics
     */
    void setup(void)
    {
      // start serial port
      Serial.begin(9600);
      Serial.println("Dallas Temperature IC Control Library Demo");
    
      // locate devices on the bus
      Serial.print("Locating devices...");
      sensors.begin();
      Serial.print("Found ");
      Serial.print(sensors.getDeviceCount(), DEC);
      Serial.println(" devices.");
    
      // report parasite power requirements
      Serial.print("Parasite power is: "); 
      if (sensors.isParasitePowerMode()) Serial.println("ON");
      else Serial.println("OFF");
      
      // Assign address manually. The addresses below will beed to be changed
      // to valid device addresses on your bus. Device address can be retrieved
      // by using either oneWire.search(deviceAddress) or individually via
      // sensors.getAddress(deviceAddress, index)
      // Note that you will need to use your specific address here
      //insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 };
    
      // Method 1:
      // Search for devices on the bus and assign based on an index. Ideally,
      // you would do this to initially discover addresses on the bus and then 
      // use those addresses and manually assign them (see above) once you know 
      // the devices on your bus (and assuming they don't change).
      if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0"); 
      
      // method 2: search()
      // search() looks for the next device. Returns 1 if a new address has been
      // returned. A zero might mean that the bus is shorted, there are no devices, 
      // or you have already retrieved all of them. It might be a good idea to 
      // check the CRC to make sure you didn't get garbage. The order is 
      // deterministic. You will always get the same devices in the same order
      //
      // Must be called before search()
      //oneWire.reset_search();
      // assigns the first address found to insideThermometer
      //if (!oneWire.search(insideThermometer)) Serial.println("Unable to find address for insideThermometer");
    
      // show the addresses we found on the bus
      Serial.print("Device 0 Address: ");
      printAddress(insideThermometer);
      Serial.println();
    
      // set the resolution to 9 bit (Each Dallas/Maxim device is capable of several different resolutions)
      sensors.setResolution(insideThermometer, 9);
     
      Serial.print("Device 0 Resolution: ");
      Serial.print(sensors.getResolution(insideThermometer), DEC); 
      Serial.println();
    }
    
    // function to print the temperature for a device
    void printTemperature(DeviceAddress deviceAddress)
    {
      // method 1 - slower
      //Serial.print("Temp C: ");
      //Serial.print(sensors.getTempC(deviceAddress));
      //Serial.print(" Temp F: ");
      //Serial.print(sensors.getTempF(deviceAddress)); // Makes a second call to getTempC and then converts to Fahrenheit
    
      // method 2 - faster
      float tempC = sensors.getTempC(deviceAddress);
      Serial.print("Temp C: ");
      Serial.print(tempC);
      Serial.print(" Temp F: ");
      Serial.println(DallasTemperature::toFahrenheit(tempC)); // Converts tempC to Fahrenheit
    }
    /*
     * Main function. It will request the tempC from the sensors and display on Serial.
     */
    void loop(void)
    { 
      // call sensors.requestTemperatures() to issue a global temperature 
      // request to all devices on the bus
      Serial.print("Requesting temperatures...");
      sensors.requestTemperatures(); // Send the command to get temperatures
      Serial.println("DONE");
      
      // It responds almost immediately. Let's print out the data
      printTemperature(insideThermometer); // Use a simple function to print out the data
    
      float tempF = sensors.getTempF(insideThermometer);
      send(msg.set((float)tempF, 2));
    
      
      // delay until next measurement (msec)
      sleep(SLEEP_TIME);
    }
    
    // function to print a device address
    void printAddress(DeviceAddress deviceAddress)
    {
      for (uint8_t i = 0; i < 8; i++)
      {
        if (deviceAddress[i] < 16) Serial.print("0");
        Serial.print(deviceAddress[i], HEX);
      }
    }
    

    Before I added the MySensors specific lines to this code, I was getting the temperature outputs in the serial monitor. After adding MySensors lines, I get a few garbage characters in the serial monitor for that node, but that's all. When I have the serial monitor running on the gateway and then power up this node, I never see anything different in the serial output.

    I've also been monitoring the MQTT topics that I configured in the gateway code and I never see any messages posted.

    I feel like I'm probably missing really simple, but I'm just not sure where to go from here. It seems that the radios do not connect between the nodes, but I'm not sure the next steps to determine if that's the case. Can somebody help me get pointed in the right direction with next steps?


  • Hero Member

    when you set

    #define MY_DEBUG
    

    it starts the serial device as well so you don't need to use

    Serial.begin(9600);
    

    The default speed for mysensors is 115200 baud so you will need to set your serial monitor to that also



  • @Boots33, thanks for the tip! That definitely gets me a little bit farther. I removed the Serial.begin line and set the speed to 115200. Now instead of garbage I'm getting this message over and over when I have the serial monitor watching the sensor node:

    Starting sensor (RNNNA-, 2.0.0)
    TSM:INIT
    TSM:RADIO:OK
    TSM:FPAR
    TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    !TSM:FPAR:FAIL
    !TSM:FAILURE
    TSM:PDT
    TSM:INIT
    TSM:RADIO:OK
    TSM:FPAR
    TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    !TSM:FPAR:FAIL
    !TSM:FAILURE
    TSM:PDT
    

    I see that something is a "FAILURE", but what? Any ideas what is going wrong at this point?


  • Contest Winner

    @JonnyDev13 if I'm not mistaken your sensor tries to connect to your gateway but the radio on your sensor isn't able to find the gateway.

    In most cases this is power related.

    1. Did you add a capacitor?
    2. How do you power the radio?


  • @TheoL, you're absolutely right. I was just about to post about that. In the instructions about Connecting the Radio to your Arduino it mentions "Refer to the notes about using a regulator or a coupling-capacitor below." The "or" in there made me think I didn't need a capacitor since maybe the regulator took care of the problem or something. I added in a capacitor and the sensor is connecting to the gateway!

    Now the gateway is at least receiving messages and passing them on to MQTT. Unfortunately, the messages don't contain any numbers. There also seems to be something wrong on the sensor node side. I don't see any of the serial prints that should be showing the temperature readings in the serial monitor:

    Here's the sensor node serial output:

    !TSM:CHKID:FAIL (ID=255)
    !TSM:FAILURE
    TSM:PDT
    TSM:INIT
    TSM:RADIO:OK
    TSM:FPAR
    TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSP:MSG:READ 0-0-255 s=255,c=3,t=8,pt=1,l=1,sg=0:0
    TSP:MSG:FPAR RES (ID=0, dist=0)
    TSP:MSG:PAR OK (ID=0, dist=1)
    TSM:FPAR:OK
    TSM:ID
    TSP:MSG:SEND 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=ok:
    TSM:ID
    TSP:MSG:SEND 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=ok:
    TSM:ID
    TSP:MSG:SEND 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=ok:
    TSM:ID
    TSP:MSG:SEND 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=ok:
    !TSM:CHKID:FAIL (ID=255)
    

    And here's some output from the gateway. (I'm not sure if they line up exactly.)

    0;255;3;0;9;TSP:MSG:FPAR REQ (sender=255)
    0;255;3;0;9;TSP:CHKUPL:OK
    0;255;3;0;9;TSP:MSG:GWL OK
    0;255;3;0;9;TSP:MSG:SEND 0-0-255-255 s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=bc:0
    0;255;3;0;9;TSP:MSG:READ 255-255-0 s=255,c=3,t=3,pt=0,l=0,sg=0:
    0;255;3;0;9;Sending message on topic: mygateway1-out/255/255/3/0/3
    0;255;3;0;9;TSP:MSG:READ 255-255-0 s=255,c=3,t=3,pt=0,l=0,sg=0:
    0;255;3;0;9;Sending message on topic: mygateway1-out/255/255/3/0/3
    0;255;3;0;9;TSP:SANCHK:OK
    0;255;3;0;9;TSP:MSG:READ 255-255-0 s=255,c=3,t=3,pt=0,l=0,sg=0:
    0;255;3;0;9;Sending message on topic: mygateway1-out/255/255/3/0/3
    0;255;3;0;9;TSP:MSG:READ 255-255-0 s=255,c=3,t=3,pt=0,l=0,sg=0:
    0;255;3;0;9;Sending message on topic: mygateway1-out/255/255/3/0/3
    0;255;3;0;9;TSP:MSG:READ 255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
    0;255;3;0;9;TSP:MSG:BC
    0;255;3;0;9;TSP:MSG:FPAR REQ (sender=255)
    

    The mygateway1-out/255/255/3/0/3 topic is receiving blank messages.

    Is there a reference somewhere about what the output failure messages mean? I feel like I could look some of these things up myself if I knew where to look.


  • Contest Winner

    @JonnyDev13 @JonnyDev13 One thing at a time.

    1. You can communicate. That's great to hear.

    I investigated your sketch. I don't see anything strange at the first glance. Maybe @mfalkvidd can help us with locating the reference, because I've seen him post that somewhere. I'd want to look them up myself, but have limited time at moment.

    What I find strange, is that your gateway is saying mygateway1-out/255/255/3/0/3 so I'd expected at least two or three MQTT messages in that topic...


  • Mod

    @TheoL reference to how to read the 2.0 output? In that case it is available in the usual place, https://forum.mysensors.org/topic/666/debug-faq-and-how-ask-for-help/4
    I have not learned how to read the 2.0 debug output yet myself.


  • Contest Winner

    @mfalkvidd That's the one. Thanx buddie!



  • @JonnyDev13
    Do you have a controller connected to the MQTT server? My thought is (not being an expert at all) that your node does not get an ID from a controller, and set it locally to 255...

    If you don't have a controller that hands out id's to nodes, set the node_id in the node sketch.


  • Contest Winner

    @LOST Not 100% positive on this one. But I have always thought that the gateway is responsible for handing out node id's. The controller assigns his own internal ID. At least that's what Domoticz is doing in mine setup.

    Otherwise assigning a static Node id couldn't work...... I think


  • Admin

    @TheoL @LOST @JonnyDev13 The GW does not assign node IDs, either you set them locally using

    #define NODE_ID 10
    

    (to be placed before

    #include <MySensors.h>
    

    )

    or your controller supports node ID assignments.

    This debug log indicates a node requesting an ID from the controller:

    TSM:ID
    TSP:MSG:SEND 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,sg=0,ft=0,st=ok:
    

    If no ID assigned after a few retries, the node will emit an error:

    !TSM:CHKID:FAIL (ID=255)
    

    and re-initialise.



  • Off Topic:
    As I said, I'm no expert at all, not even experienced in MySensors..but in https://www.mysensors.org/about/network it says: Each node is assigned a unique sensorId or address that is used for sending and receiving point-to-point messages. You can assign a static sensorId or let the controller automatically assign one to the sensor. AUTO-mode configures the sensor to request a sensorId from the controller and is the default option for all the examples that we provide. The sensor stores the assigned sensorId in its non-volatile memory to ensure the correct sensorId persists across power transitions.



  • Ok, @tekka. Thanks.



  • Ok, now we're cooking! @tekka, thanks for explaining some of the details that I was missing. I'm sure I read that before, but I guess I swapped "gateway" with "controller" in my head, assuming that the sensor node would be assigned an id by the gateway.

    I placed the following in my sensor node's sketch:

    #define MY_NODE_ID 2
    

    This avoided any errors, but I still wasn't seeing the correct message come through MQTT.

    Not sure if it was required, but I ended up having to add

    #define MY_PARENT_NODE_ID 1
    

    to the sensor node's sketch, and

    #define MY_NODE_ID 1
    

    to the gateway node's sketch. Once I did that, the temperature readings started showing up in MQTT!

    Thanks for the help everybody. I still have quite a bit to learn, but getting a working sensor sending data all the way through the gateway to MQTT was the biggest hurdle to really making progress on implementing these. THANK YOU!


Log in to reply
 

Suggested Topics

  • 3
  • 5
  • 1
  • 2
  • 6

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts