Serial gateway with the API
-
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
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
-
In the dev-branch you can disable radio support for gw-nodes completely.
-
@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
-
@skatun
You just do sending the same way on gateway as on the nodes.send(msgTemp.set(temperature, 1))