Dev serial gateway - usb connection to raspberry pi (OpenHab and/or HomeAssistant)



  • Hello.

    I'm trying to connect my Arduino Uno with rf433 receiver and some data received from another Uno and push this data to raspberry pi (open hab - for example). I've used this tutorial http://forum.mysensors.org/topic/1194/tutorial-openhab-with-serial-gateway

    So far my readings in serial monitor looks like this:

    ±'Ú˘ţ0;255;3;0;9;Starting gateway (R-NGA-, 2.0.0-beta)
    0;255;3;0;14;Gateway startup complete.
    0;255;3;0;11;Weather Station Sensor
    0;255;3;0;12;1.0
    0;0;0;0;8;
    0;2;0;0;7;
    0;1;0;0;6;
    0;4;0;0;7;
    0;3;0;0;6;
    0;5;0;0;6;
    0;255;3;0;9;Init complete, id=0, parent=0, distance=0
    0;0;1;0;4;0.0
    0;3;1;0;0;0.0
    0;3;1;0;0;24.0
    0;4;1;0;1;59.0
    0;5;1;0;0;15.5
    0;0;1;0;4;1004.0
    0;3;1;0;0;24.0
    0;4;1;0;1;59.0
    0;5;1;0;0;15.5
    0;0;1;0;4;1004.0
    

    Unfortunatelly I can't see enything in raspberry pi and openhab.

    My Arduino Code:

    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable serial gateway
    #define MY_GATEWAY_SERIAL
    
    // FLash leds on rx/tx/err
    #define MY_LEDS_BLINKING_FEATURE
    // Set blinking priod
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Enable inclusion mode
    #define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    #define MY_INCLUSION_BUTTON_FEATURE
    
    // 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 Node Id number
    #define MY_NODE_ID 101
    
    #include <Wire.h> // use Wire library for protocol i2c (A4 = SDA & A5 = SCL)
    #include <VirtualWire.h> // use Virtual library for decode signal from Rx module
    #include <SPI.h>
    #include <MySensor.h>
    #include <DHT.h>
    
    // ---------------------------------------------------------------------------------------------------
    // Child sensor ids
    #define CHILD_ID_BARO 0
    #define CHILD_ID_TEMP1 1
    #define CHILD_ID_HUM1 2
    #define CHILD_ID_TEMP2 3
    #define CHILD_ID_HUM2 4
    #define CHILD_ID_TEMP3 5 //Dew Point
    
    // ----------------------------------------------------------------------------------------------------
    // DHT-11/22
    //#define HUMIDITY_SENSOR_DIGITAL_PIN 3
    
    //DHT dht;
    //float lastTemp;
    //float lastHum;
    //boolean metric = true;
    
    MyMessage msgPressure(CHILD_ID_BARO, V_PRESSURE);
    MyMessage msgHum1(CHILD_ID_HUM1, V_HUM);
    MyMessage msgTemp1(CHILD_ID_TEMP1, V_TEMP);
    MyMessage msgHum2(CHILD_ID_HUM2, V_HUM);
    MyMessage msgTemp2(CHILD_ID_TEMP2, V_TEMP);
    MyMessage msgTemp3(CHILD_ID_TEMP3, V_TEMP);
    
    
    // Sensors 
    int humidity;
    int temp;
    int tempf;
    int pres;
    int rain;
    char MsgReceived[21]; 
    //int led = 8; //pin for LED
    
    float tF;
    float dP;
    float dPF;
    float hT;
    
    void setup() 
    {
      
      //Serial.begin(115200); //Starting serial communication
      //Serial.println("Program started");
      //Serial.print(" WS :");
      //Serial.print("\t");
      //Serial.print("Rain Drop\t");
      //Serial.print("Pressure \t");
      //Serial.print("Air Hum\t");
      //Serial.print("\t");
      //Serial.print("Temp \t");
      //Serial.print("Dew Point\t");
      //Serial.println("Heat Index: ");
        
      // VirtualWire 
      // Bits per sec
      vw_setup(2000);
      // set pin for connect receiver module 
      vw_set_rx_pin(9);  
      // Start the receiver PLL running
      vw_rx_start();       
    
    //dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
    
    
    } // END void setup
    
    void presentation()
    {
       // Send the sketch Version Information to the Gateway
       sendSketchInfo("Weather Station Sensor", "1.0");
    
       // Register all sensors to gw (they will be created as child devices)
       present(CHILD_ID_BARO, S_BARO);
       present(CHILD_ID_HUM1, S_HUM);
       present(CHILD_ID_TEMP1, S_TEMP);
       present(CHILD_ID_HUM2, S_HUM);
       present(CHILD_ID_TEMP2, S_TEMP);
       present(CHILD_ID_TEMP3, S_TEMP);
    }
    
    
    void loop()
    {
      
      uint8_t buf[VW_MAX_MESSAGE_LEN];
      uint8_t buflen = VW_MAX_MESSAGE_LEN;
      //Taking the data from the control base
      if (vw_get_message(buf, &buflen)) //Non-blocking
      {
        //digitalWrite(led, HIGH);
        //delay(100);
        int i;
        // Message with a good checksum received, dump it. 
        for (i = 0; i < buflen; i++)
        {            
          // Fill Msg Char array with corresponding 
          // chars from buffer.   
          MsgReceived[i] = char(buf[i]);
          //Serial.print(MsgReceived[i]);
        }
        sscanf(MsgReceived, "%d,%d,%d",&pres, &humidity, &temp, &rain); // Converts a string to an array
        //digitalWrite(led, LOW); 
        //Serial.print(" WS : ");
        //Serial.print(rain);
        //Serial.print(" %\t");
        //Serial.print("\t");
        //Serial.print(pres);
        //Serial.print(" hPa \t");
        //Serial.print(humidity);
        //Serial.print(" %\t");
        //Serial.print("\t");
        //Serial.print(temp);
        //Serial.print("*C \t");
        dP = dewPointFast(temp, humidity);
        //Serial.print(dP);
        //Serial.print("*C \t");
        //Serial.print(" \t");
        hT = heatIndex(temp,humidity);
        //Serial.print(hT);
        //Serial.println(" *C");
        //Serial.println((char*)buf);
        memset( MsgReceived, 0, sizeof(MsgReceived));// This line is for reset the StringReceived
      }
    
      send(msgPressure.set(pres, 1));
      send(msgTemp2.set(temp, 1));
      send(msgHum2.set(humidity, 1));
      send(msgTemp3.set(dP, 1));
    
      
    }
    
    // delta max = 0.6544 wrt dewPoint()
    // 6.9 x faster than dewPoint()
    // reference: http://en.wikipedia.org/wiki/Dew_point
    double dewPointFast(double celsius, double humidity)
    {
     double a = 17.271;
     double b = 237.7;
     double temp = (a * celsius) / (b + celsius) + log(humidity*0.01);
     double Td = (b * temp) / (a - temp);
     return Td;
    }
    
    double heatIndex(double temp, double humidity)
    {
      double c1 = -42.38, c2 = 2.049, c3 = 10.14, c4 = -0.2248, c5= -6.838e-3, c6=-5.482e-2, c7=1.228e-3, c8=8.528e-4, c9=-1.99e-6  ;
      tempf = (temp*1.8 + 32);  //  Celsius to Fahrenheit
      double T = tempf;
      double R = humidity;
    
      double A = ((c5 * T) + c2) * T + c1;
      double B = ((c7 * T) + c4) * T + c3;
      double C = ((c9 * T) + c8) * T + c6;
    
      double rv = (C * R + B) * R + A;
      rv = ((((rv)-32)*5)/9);  //  converting to C
      return rv;
    }
    

    What I'm missing???
    FYI I'm quite new in arduino and programming.

    Thank you in advance for help.

    All the best
    Robert


  • Plugin Developer

    @robertmt

    Hi!

    Did you have the serial monitor active in all your tests? The serial interface is exclusive so you can't have the serial monitor active on the gateway if you want it to talk via serial to a computer.

    Consider using the markdown support of the forum, and post logs and sketches as code blocks. Makes it easier to read. Three backticks on an empty line before and after the code will do that.



  • Hello.

    Serial Monitor was active while connected on usb laptop with Arduino IDE. That is where the data posted comes from.
    Not really sure what is happening on Raspberry Pi side.
    Minicom gives me nothing...


  • Plugin Developer

    @robertmt

    Have you looked at log output from openhab?

    Have you checked that the user that runs openhab have access to the serial port device?



  • Part of my OpenHab debug log:

    12:48:51.378 [DEBUG] [i.internal.GenericItemProvider:154  ] - Processing binding configs for items from model 'demo.items'
    12:48:51.388 [DEBUG] [i.internal.GenericItemProvider:419  ] - Couldn't find ItemFactory for item 'Arduino' of type 'String'
    12:48:51.393 [DEBUG] [i.internal.GenericItemProvider:419  ] - Couldn't find ItemFactory for item 'Temp2' of type 'Number'
    12:48:51.398 [DEBUG] [i.internal.GenericItemProvider:419  ] - Couldn't find ItemFactory for item 'Hum2' of type 'Number'
    12:48:51.464 [DEBUG] [i.internal.GenericItemProvider:133  ] - Read items from model 'demo.items'
    12:48:51.492 [DEBUG] [o.o.c.i.items.ItemRegistryImpl:137  ] - Item provider 'GenericItemProvider' has been added.
    12:48:51.500 [DEBUG] [i.internal.GenericItemProvider:133  ] - Read items from model 'demo.items'
    

    I have some progress on minicom... reading captured to file and it is showing same thing as serial Arduini IDE.

    0;255;3;0;9;Starting gateway (R-iŠÚŞŞr‚Rđ0;255;3;0;9;Starting gateway (R-NGA-, 2.0.0-beta)
    0;255;3;0;14;Gateway startup complete.
    0;255;3;0;11;Weather Station Sensor
    0;255;3;0;12;1.0
    0;0;0;0;8;
    0;2;0;0;7;
    0;1;0;0;6;
    0;4;0;0;7;
    0;3;0;0;6;
    0;5;0;0;6;
    0;255;3;0;9;Init complete, id=0, parent=0, distance=0
    0;0;1;0;4;0.0
    0;3;1;0;0;0.0
    0;4;1;0;1;0.0
    0;5;1;0;0;0.0
    0;0;1;0;4;0.0
    0;3;1;0;0;0.0
    0;4;1;0;1;0.0
    0;5;1;0;0;0.0
    0;0;1;0;4;0.0
    0;3;1;0;0;0.0
    0;4;1;0;1;0.0
    0;5;1;0;0;0.0
    .... (200 lines after)
    0;0;1;0;4;1007.0
    0;3;1;0;0;23.0
    0;4;1;0;1;55.0
    0;5;1;0;0;13.5
    0;0;1;0;4;1007.0
    0;3;1;0;0;23.0
    0;4;1;0;1;55.0
    0;5;1;0;0;13.5
    0;0;1;0;4;1007.0
    

    So... looks like there is something coming out from Arduino but OpenHab is still not happy.

    Why in this output first number is 0... shouldn't be 101 (as declared in
    // Set Node Id number
    #define MY_NODE_ID 101

    What is a proper config for a demo.items related to Arduino code... Can't find any informations on a net.


  • Plugin Developer

    @robertmt

    Please edit your posts and put the logs and sketch inside code block markdown. It's a struggle to read it right now.

    It looks like you have attached sensors directly to the serial gateway, which is possible with the dev branch. The gateway will always have node id 0. I don't think it's possible to change that.


  • Plugin Developer

    @robertmt

    Someone else should answer the openhab configuration specific questions. It's a long time since I used openhab.

    I think you should try to verify somehow that openhab can read the serial output. If you can see that, you know that the problem lies within your config, and not earlier.



  • Hi.

    I have some progress. I can see data coming in terminal ...

    [INFO] [ runtime.busevents           ]   -   Arduino state updated to 0;0;1;0;4;1009.0
    0;1;1;0;0;22.0
    0;2;1;0;1;61.0
    

    and keep updating...
    (only 3 nodes so far)

    However on website still nothing... I assume there is something wrong with openhab config.

    What I did...


Log in to reply
 

Suggested Topics

  • 1
  • 2
  • 3
  • 10
  • 2
  • 5

1
Online

11.2k
Users

11.1k
Topics

112.5k
Posts