Home Assistant errors with serial gateway



  • I'm getting WARNING: Gateway /dev/ttyUSB0 not ready after 15.0 secs
    But serial data is getting through, as it shows up later in the log.
    2020-04-17 16:05:35 DEBUG (MainThread) [mysensors] Receiving 2;255;3;0;0;86
    2020-04-17 16:05:35 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: node 2 child 255
    2020-04-17 16:05:35 DEBUG (MainThread) [mysensors] Receiving 2;1;1;0;38;2.84
    2020-04-17 16:05:35 WARNING (MainThread) [mysensors] Child 1 is unknown

    Any idea why the gateway isn't getting set up correctly?

    Gateway is an Arduino mini, baudrate 38400. Using standard gateway sketch.
    Home Assistant is latest version, 32bit, running on PI 3B+.



  • @KevinT said in Home Assistant errors with serial gateway:

    2020-04-17 16:05:35 WARNING (MainThread) [mysensors] Child 1 is unknown

    This could be caused by incomplete presentation of your sketch. Does your sketch fulfill the requirements as for example shown here:
    https://www.home-assistant.io/integrations/sensor.mysensors/
    https://www.google.com/search?q=mysensors+home+assistant



  • Thanks.

    I was missing 2 things, the presentation of S_MULTIMETER, the battery voltage I also send out, and the initial value send in the main loop. (Funny, I had read these myself but ignored them thinking I had a timeout problem.)

    For the initial value send, I have 2 sensors, can I just read back the value of the last sensor sent, or do I have to verify all of them?
    (I am assuming this is just a step to ensure the controller is ready before continuing?)

    Also, though everything now works, I still get the timeout (not ready) on the serial port. Is this normal?

    Also, 2 strange warnings, node 0 (controller?) and node 1 (gateway) missing sketch names?

    2020-04-18 09:57:00 DEBUG (SyncWorker_16) [mysensors.persistence] Loading sensors from persistence file /config/mysensors1.pickle
    2020-04-18 09:57:00 DEBUG (SyncWorker_6) [mysensors.persistence] Saving sensors to persistence file /config/mysensors1.pickle
    **2020-04-18 09:57:00 DEBUG (MainThread) [homeassistant.components.mysensors.helpers] Node 1 is missing sketch name
    2020-04-18 09:57:00 DEBUG (MainThread) [homeassistant.components.mysensors.helpers] Node 0 is missing sketch name**
    2020-04-18 09:57:00 INFO (MainThread) [homeassistant.components.mysensors] Adding new devices: [<Entity Temperature Sensor 2 1: None>, <Entity Temperature Sensor 2 0: None>]
    2020-04-18 09:57:00 DEBUG (MainThread) [homeassistant.components.mysensors.device] Entity update: Temperature Sensor 2 1: value_type 38, value = 2.85
    2020-04-18 09:57:01 DEBUG (MainThread) [homeassistant.components.mysensors.device] Entity update: Temperature Sensor 2 0: value_type 0, value = 21.44
    2020-04-18 09:57:01 INFO (MainThread) [mysensors.gateway_serial] Trying to connect to /dev/ttyUSB0
    2020-04-18 09:57:01 INFO (MainThread) [mysensors] Connected to Serial<id=0x6b041470, open=True>(port='/dev/ttyUSB0', baudrate=38400, bytesize=8, parity='N', stopbits=1, timeout=0, xonxoff=False, rtscts=False, dsrdtr=False)
    2020-04-18 09:57:03 DEBUG (MainThread) [mysensors] Receiving 2;0;1;0;0;21.44
    2020-04-18 09:57:03 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: node 2 child 0
    2020-04-18 09:57:03 DEBUG (MainThread) [homeassistant.components.mysensors.device] Entity update: Temperature Sensor 2 0: value_type 0, value = 21.44
    2020-04-18 09:57:10 DEBUG (SyncWorker_11) [mysensors.persistence] Saving sensors to persistence file /config/mysensors1.pickle
    **2020-04-18 09:57:16 WARNING (MainThread) [homeassistant.components.mysensors.gateway] Gateway /dev/ttyUSB0 not ready after 15.0 secs so continuing with setup**
    2020-04-18 09:57:35 DEBUG (MainThread) [mysensors] Receiving 2;0;1;0;0;21.44
    2020-04-18 09:57:35 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: node 2 child 0
    2020-04-18 09:57:35 DEBUG (MainThread) [homeassistant.components.mysensors.device] Entity update: Temperature Sensor 2 0: value_type 0, value = 21.44
    2020-04-18 09:57:40 DEBUG (SyncWorker_2) [mysensors.persistence] Saving sensors to persistence file /config/mysensors1.pickle
    


  • First, please use the code formatting for your posts. That makes it easier to read.
    I don't know about this timeout. How is the gateway working when you connect it to your PC?
    For the sketch name, does your sketch send it? Please post your sketch code



  • Hi electrik,
    Yes, my nodes send the sketch name within the presentation function.
    As for the gateway, I have not set up a sketch name, the example I found did not implement this, so I didn't think it
    was necessary?

    I manually named the gateway node in the configuration.yaml file, and the "missing sketch name" message no longer appears in the log. I guess, I'll add an entry for node 0 (controller) as well .

    I'm still getting the "USB0 not ready after 15.0 secs" at startup, but all seems to work regardless.

    I connected the gateway to my pc using mycontroller, it all works fine. Logs look normal.

    Here is the code for one of my nodes, a temperature node with Arduino mini & RFM69 radio, running on battery.

    
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    #define MY_BAUD_RATE 38400
    
    // Enable and select radio type attached
    //#define MY_RADIO_RF24
    #define MY_RADIO_RFM69
    #define MY_IS_RFM69HW
    #define MY_RFM69_FREQUENCY  RFM69_915MHZ
    
    #include <MySensors.h>  
    #include <DallasTemperature.h>
    #include <OneWire.h>
    
    #define COMPARE_TEMP 0 // Send temperature only if changed? 1 = Yes 0 = No
    
    #define ONE_WIRE_BUS 8 // Pin where dallas sensor is connected 
    
    #define CHILD_ID_TEMP 0
    #define CHILD_ID_BATT 1
    
    // function protos
    void ReadBat(double& b, uint8_t& bPct);
    
    unsigned long SLEEP_TIME = 300000;    // Sleep time between reads (5min) (in milliseconds)
    const int BAT_V = A0;                 // battery voltage, AnaIn 0
    
    OneWire oneWire(ONE_WIRE_BUS);        // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
    DallasTemperature sensors(&oneWire);  // Pass the oneWire reference to Dallas Temperature. 
    
    float lastTemperature;
    double bat, lastBat=0.0;
    uint8_t batPct;
    int numSensors=0;
    bool receivedConfig = false;
    bool metric = true;
    bool initialValuesSent = false;
    bool initialValTempSent = false;
    bool initialValBatSent = false;
    
    // Initialize message objects
    MyMessage msg(CHILD_ID_TEMP, V_TEMP);
    MyMessage msgBatt(CHILD_ID_BATT, V_VOLTAGE);
    
    void before()
    {
      // Startup up the OneWire library
      sensors.begin();
    }
    
    void setup()  
    { 
      sensors.setWaitForConversion(false);
      // requestTemperatures() will not block current thread
      Serial.print("Found ");
      Serial.print(sensors.getDeviceCount(), DEC);
      Serial.println(" temperature devices.");
      sensors.requestTemperatures();
    }
    
    void presentation() {
      Serial.println("Sending presentation");
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Temperature Sensor", "1.2");
      // Present all sensors to controller
      present(CHILD_ID_TEMP, S_TEMP, "Bed room Temperature");
      present(CHILD_ID_BATT, S_MULTIMETER, "Bed room node Voltage");
    }
    
    void loop()     
    {     
      int16_t conversionTime = 0;
      float temperature = 0;
      
      if (!initialValuesSent) {
        Serial.println("Sending initial value");
        // Read in the battery voltage
        ReadBat(bat, batPct);
        // get temperature conversion time
        conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
        wait(conversionTime);
        // Fetch temperature
        temperature = sensors.getTempCByIndex(0);
        // send the temperature reading
        // set(float value, uint8_t decimals)
        send(msg.set(temperature, 2));
        Serial.println("Requesting initial Temp value from controller");
        request(CHILD_ID_TEMP, V_TEMP);
        wait(2000, C_SET, V_TEMP);
        // send bat voltage
        send(msgBatt.set(bat, 2));
        Serial.println("Requesting initial Batt value from controller");
        request(CHILD_ID_BATT, V_VOLTAGE);
        wait(2000, C_SET, V_VOLTAGE);
      }
    //  {
      else {
        // Fetch temperatures from Dallas sensors (non-blocking)
        sensors.requestTemperatures();
        // Read in the battery voltage
        ReadBat(bat, batPct);
      
        // query conversion time and sleep until conversion completed
        conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
        
        // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
        sleep(conversionTime);
      
        // Read temperature and send to controller 
        // Fetch temperature
        temperature = sensors.getTempCByIndex(0);
        Serial.println("temperature: ");
        Serial.println(temperature);
      
        // Only send data if temperature has changed and no error
        #if COMPARE_TEMP == 1
        if (lastTemperature != temperature && temperature != -127.00 && temperature != 85.00) {
        #else
        if (temperature != -127.00 && temperature != 85.00) {
        #endif
          // Send in the new temperature
          // set(float value, uint8_t decimals)
          send(msg.set(temperature, 2));
          // Save new temperatures for next compare
          lastTemperature=temperature;
        }
        // Send in the new battery level
        sendBatteryLevel(batPct);
        send(msgBatt.set(bat, 2));
        // Save the battery level for next compare
        lastBat = bat;
        Serial.println("Sleep...");
        sleep(SLEEP_TIME);
      }
    }
    
    void receive(const MyMessage &message) {
      if (message.isAck()) {
         Serial.println("This is an ack from gateway");
      }
    
      if (message.type == V_TEMP) {
        if (!initialValTempSent) {
          Serial.println("Received initial temp value from controller");
          initialValTempSent = true;
        }
      }
      else if (message.type == V_VOLTAGE) {
        if (!initialValBatSent) {
          Serial.println("Received initial bat value from controller");
          initialValBatSent = true;
        }
      }
      if (initialValTempSent && initialValBatSent)
        initialValuesSent = true;
    }
    
    // b - battery voltage
    // bPct - battery percent
    void ReadBat(double& b, uint8_t& bPct)
    {
      long sumBat=0;
      int i;
    
      // take average over 64 readings
      for (i = 0; i < 64; ++i) {
        // read & sum battery voltage
        sumBat += analogRead(BAT_V);
      }
      sumBat = sumBat >> 6;      // shift 6 -> divide by 64
      b = sumBat*3.3/1023.0;
      bPct = (uint8_t)(sumBat*100.0/1023.0);
    }
    

    Here is the serial gateway sketch:

    #include <SoftwareSerial.h>
    SoftwareSerial softSerial(8, 9); // RX, TX
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    #define MY_DEBUGDEVICE softSerial
    // You also need to create softSerial in setup()
    
    // Enable and select radio type attached
    //#define MY_RADIO_RF24
    //#define MY_RADIO_NRF5_ESB
    //#define MY_RADIO_RFM95
    #define MY_RADIO_RFM69
    #define MY_IS_RFM69HW
    #define MY_RFM69_FREQUENCY  RFM69_915MHZ
    
    
    // Set LOW transmit power level as default, if you have an amplified NRF-module and
    // power your radio separately with a good regulator you can turn up PA level.
    //#define MY_RF24_PA_LEVEL RF24_PA_LOW
    
    // Enable serial gateway
    #define MY_GATEWAY_SERIAL
    
    // Define a lower baud rate for Arduinos running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender)
    #if F_CPU == 8000000L
    #define MY_BAUD_RATE 38400
    #endif
    
    // Enable inclusion mode
    #define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    //#define MY_INCLUSION_BUTTON_FEATURE
    
    // Inverses behavior of inclusion button (if using external pullup)
    //#define MY_INCLUSION_BUTTON_EXTERNAL_PULLUP
    
    // Set inclusion mode duration (in seconds)
    #define MY_INCLUSION_MODE_DURATION 60
    // Digital pin used for inclusion mode button
    //#define MY_INCLUSION_MODE_BUTTON_PIN  3
    
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Inverses the behavior of leds
    //#define MY_WITH_LEDS_BLINKING_INVERSE
    
    // Flash leds on rx/tx/err
    // Uncomment to override default HW configurations
    //#define MY_DEFAULT_ERR_LED_PIN 4  // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN  6  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  5  // the PCB, on board LED
    
    #include <MySensors.h>
    
    void setup()
    {
      softSerial.begin(38400);
    }
    
    void presentation()
    {
    	// Present locally attached sensors
    }
    
    void loop()
    {
    	// Send locally attached sensor data here
    }
    

Log in to reply
 

Suggested Topics

50
Online

11.4k
Users

11.1k
Topics

112.6k
Posts