Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. General Discussion
  3. Serial gateway with the API

Serial gateway with the API

Scheduled Pinned Locked Moved General Discussion
4 Posts 2 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • skatunS Offline
    skatunS Offline
    skatun
    wrote on last edited by
    #1

    Hi
    I am pretty new to the mysensor project, but I really like it!

    So I have a few questions regarding my setup. So I have an Raspberry Pi running openhab, to this I am trying to connect 4 arduinos, 3 of them through usb and the last one through voltage converter and serial on GPIO. I am currently making 6 sensor nodes IMG_20151111_073443.jpg

    Each nodes has 2 pir sensors, dht22,light sensor, sound sensor, and co2 sensor. Due to the processing load, my idea was to split these sensors over two arduino uno(atmega 328). Is that a good idea? (The problem is that I am trying to detect which of the two pir sensor were triggered first to see if you are going in or out of the room, hence they will get triggered with >50ms interval).

    Then i have the serial on GPIO arduino nano(due to the fact it was easier to solder 12m cable to the gpio pins instead of terminating it to the usb.) which reads 4 buttons and controlls 4 solid state relays for my bar.

    Then finally I have a arduino controlling several led strips, connected through USB.

    So as a start I managed to get the serial gateway to work by just writing serial.print("12,7,1,0,23.6\n") but now I want to expand it to use real sensors and this is when i get stuck.... Do I need to throw away the libraries since these only work with the radio modem, or should i rewrite them to work with the serial connection or how do I proceed? I need to set the baudrate and give them static node ID. Below is my modified code, that does not work..

    #include <SPI.h>
    #include <MySensor.h>  
    #include <DHT.h>  
    
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define HUMIDITY_SENSOR_DIGITAL_PIN 11
    unsigned long SLEEP_TIME = 1000; // Sleep time between reads (in milliseconds)
    
    MySensor gw;
    DHT dht;
    float lastTemp;
    float lastHum;
    boolean metric = true; 
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    
    
    void setup()  
    { 
      gw.begin(NULL,12);
      dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
    
      // Send the Sketch Version Information to the Gateway
      gw.sendSketchInfo("Humidity", "1.0");
    
      // Register all sensors to gw (they will be created as child devices)
      gw.present(CHILD_ID_HUM, S_HUM);
      gw.present(CHILD_ID_TEMP, S_TEMP);
      
      metric = gw.getConfig().isMetric;
    }
    
    void loop()      
    {  
      delay(dht.getMinimumSamplingPeriod());
    
      float temperature = dht.getTemperature();
      if (isnan(temperature)) {
          Serial.println("Failed reading temperature from DHT");
      } else if (temperature != lastTemp) {
        lastTemp = temperature;
        if (!metric) {
          temperature = dht.toFahrenheit(temperature);
        }
        gw.send(msgTemp.set(temperature, 1));
        Serial.print("T: ");
        Serial.println(temperature);
      }
      
      float humidity = dht.getHumidity();
      if (isnan(humidity)) {
          Serial.println("Failed reading humidity from DHT");
      } else if (humidity != lastHum) {
          lastHum = humidity;
          gw.send(msgHum.set(humidity, 1));
          Serial.print("H: ");
          Serial.println(humidity);
      }
    
      gw.sleep(SLEEP_TIME); //sleep a bit
    }
    

    Thanks for any feedback

    1 Reply Last reply
    0
    • hekH Offline
      hekH Offline
      hek
      Admin
      wrote on last edited by
      #2

      In the dev-branch you can disable radio support for gw-nodes completely.

      1 Reply Last reply
      0
      • skatunS Offline
        skatunS Offline
        skatun
        wrote on last edited by
        #3

        @skatun said:

        gw.send(msgTemp.set(temperature, 1));

        So if I understand you correctly in the development version the method gw.send will then be equal to :
        Serial.print(GwId,NodeID,1,0,msgTemp.set(temperature, 1)\n)

        And in the examples I will then just comment out all the serial.print statements or?

        Thanks

        1 Reply Last reply
        0
        • hekH Offline
          hekH Offline
          hek
          Admin
          wrote on last edited by
          #4

          @skatun
          You just do sending the same way on gateway as on the nodes.

          send(msgTemp.set(temperature, 1))

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          15

          Online

          11.7k

          Users

          11.2k

          Topics

          113.1k

          Posts


          Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • MySensors
          • OpenHardware.io
          • Categories
          • Recent
          • Tags
          • Popular