Serial Gateway



  • Hi
    I am struggling to figure out how to use the serial API, the protocol is easy to understand, but how to implement is harder.

    I have an arduino nano that i would like to use as the gateway, to this i have 6 dht11 humidity/temperature sensors attached and 4 led strips. The ledstrips currently uses the neopixel library.

    The nano is attached to a rpi running openhab through usb(maybe i should use the serial on gpio instead?), i have made simple arduino sketch that test the serial protocol Serial.print(13;7;1;0;2;1\n) and the open hab intpretates it nicely. But now I am stuck, how can i modify the humidity code to send it out on serial protocol? And can I somehow make an array of DHT object and loop through them? And how can i combine the neopixel into the serial.api? How should the message look like coming into the serial from openhab?

    Any help is highly appreciated:)


  • Admin

    @skatun

    Is the DHT11 sensors connected directly to the arduino, that is connected to the r-pi?

    In that case, you can use dev branch, as it has support for adding sensors directly to the GW, and run without a radio connected.



  • Hi @skatun

    The Gateway does all the interpreting from the Nodes; so no need to modify the Humidity example sketch to send over serial. When the Humidity Node transmits the data to the Serial Gateway, the gateway will give you the output. See here for the MySensors Serial API (which is what you have, serial gateway. Same goes though for MQTT and Ethernet) for how your message is structured. I can't help on the OpenHAB side of things unfortunately, never had much luck with it. Hoping OpenHAB2 is more friendly.

    Good luck!



  • @tbowmo Yes it is connected directly to nano. When i have 6 nodes, will you collect them in an array or define them 6 objects? Do you have a link to dev branch?



  • @drock1985 I can help you with the openhab binding.. How can i modify this code so that it prints it out on serial instead of transmitting on RF?



  • This is how i have normally done similiar task before i started looking into mysensor.

    #include "DHT.h"
    
    DHT dht;
    
    pinsDHT = (2,4,7,8,10,12)
    childNode = (0,1,2,3,4,5)
    int GatewayID = 1
    
    void setup()
    {
      Serial.begin(9600);
        for (int i=0 ;i<6:i++) {
                   dht(i).setup(pinsDHT(i)); // data pin 2
        }
    }
    
    void loop()
    {
      //delay(dht.getMinimumSamplingPeriod());
     for (int i=0 ;i<6:i++) {
      Serial.print(GatewayID);
      Serial.print(",");
      Serial.print(childNode(i));
      Serial.print(",");
      Serial.print(1);
      Serial.print(",");
      Serial.print(S_TEMP);
      Serial.print(",");
      Serial.print(dht(i).getTemperature());
      Serial.print("\n");
    
    //debug
     Serial.println();
    
    
      Serial.print(GatewayID);
      Serial.print(",");
      Serial.print(childNode(i));
      Serial.print(",");
      Serial.print(1);
      Serial.print(",");
      Serial.print(S_HUM);
      Serial.print(",");
      Serial.print(dht(i).getHumidity());
      Serial.print("\n");
    
    //debug
     Serial.println();
    }
      
    }```

  • Admin

    @skatun

    Mysensors is build on a radio network, where you have a gateway connecting the radio network, to a controller of some sort (OpenHAB).

    When people talks about "Nodes" they mean independent arduinos with a radio, each with one (or more) sensor "children". These nodes can then be placed all over the house, or what ever you want to monitor.

    From what I undestand, you have another setup, where you have a number of DHT11 sensors connected to one arduino, which you want to act as a "GW" from the before mentioned DHT11 sensors, to OpenHAB. And you do not want to use the radio links. In that case, you need to use development branch of Mysensors, which is available on github : https://github.com/mysensors/Arduino (Default branch is development)



  • @tbowmo From that developers page i get the libraries, but somehow i can not find the serial tutorial for DHT11. I found this: link

    Yes and you are completly right ""Nodes" they mean independent arduinos" ,These nodes can then be placed all over the house,. However i had the chance when i rebuilt my flat my flat to run empty pipes all over the place to my fusebox. Since arduino needs power I dont see why i should run 2 wires, when i can run4 wires and skip the hole RF part.

    When I am finished my system would look like:

    1 arduino Mega in fusebox with 6 dht22 sensors ,12 motion sensors, 6 light sensor, 6CO sensors, 4 led strips connected to it. USB to RPI(0.3m)
    1 arduino micro 3.3V under kitchen, with ledstrip , a servo(gate for roomba), 1 IR transmitter RS485 or serial to RPI(8m)
    1 arduino micro 3.3V in bar with led strip, 4 relays and 4 buttons RS485 or serial to RPI(14m)
    1 arduino micro 3.3V in tv bench, ledstrip,1 relay for tv lift and 2 butttons RS485 or serial to RPI( 9m)
    1 arduino micro 3.3V in hallway,ledstrip,1 relay for electric wardrobe and 3 buttons RS485 or serial to RPI(2m)
    1 arduino micro 3.3V at balcony, ledstrip,7 relays for hetater, rollers,BBQ,hammock etc, 6 buttons RS485 or serial to RPI(17m)

    But currently i am just installing the the arduino nano in fusebox with a ledstrip and dht11 sensor to it. Start simple...


  • Admin

    @skatun

    As I said, there are not that much documentation on running without radio 🙂 If I remember right, you could take the basic DHT11 example, remove radio stuff, and add a MY_SERIAL_GATEWAY define (look in the code to see the right names of the defines).

    However, one thing regarding your setup, what is the distance from the arduino mega, to your DHT11 sensors? I don't think they are meant to be used with long cable runs. Also the LED strips, are they PWM controlled? How about RF noise emiting from those wire runs?

    You could probably use rs485 as protocol for mysensors (does require arduino at each node).


Log in to reply
 

Suggested Topics

  • 4
  • 14
  • 9
  • 933
  • 2
  • 274

28
Online

11.2k
Users

11.1k
Topics

112.5k
Posts