How to add a sensor to the serial gateway
-
I think you have to add the gateway as hardware in domoticz. Then when the gateway recieve info from the node/sensor its transferred into domoticz. If you have connected the node/sensor through the GPIO i think you need to create some sort of virtual device and program this in domoticz, but then the gateway are not used. The best way is Domoticz -> Gateway -> Sensors.
The MySensors use the radio to talk to the gateway... i dont know how to do that with a wire/usb.
-
Thanks for your post. Aha I thought that working without radio was the difference between serial and ethernet gateways. I've ordered some nRF24L01+. modules, probably getting them in a couple of days.
So I'll have to connect one of those to the gateway and one to the arduino Uno holding my moisture sensors?
-
Thanks for your post. Aha I thought that working without radio was the difference between serial and ethernet gateways. I've ordered some nRF24L01+. modules, probably getting them in a couple of days.
So I'll have to connect one of those to the gateway and one to the arduino Uno holding my moisture sensors?
@Bram81 yes.... no way around it. the controller talks with the gateway through the USB (Serial)
or Ethernet (Ethernet gateway) but the gateway communicates with the sensor nodes through the nrf modules. -
-
Thanks everybody! Got the serial gateway working and it's being picked up by domoticz. Now another Arduino Uno is holding a moisture sensor, it's communicating with the gateway, but Domoticz sees the sensor as a lamp so it's not logging the sensor output. The sensor is a YL-38. Is there a way to fix this or is this type simply not supported by Domoticz?
-
Hi!
Is the sensor presented correctly - what does the domoticz log say when you power up the sensor?
Do you see anything in the domoticz and or gateway log when sending temp-values? -
Hi!
Is the sensor presented correctly - what does the domoticz log say when you power up the sensor?
Do you see anything in the domoticz and or gateway log when sending temp-values?@sundberg84 Hey!
Domoticz log shows:
015-07-01 15:44:03.331 MySensors: Gateway Ready...
2015-07-01 15:44:28.776 Hardware Monitor: Fetching data (System sensors)
2015-07-01 15:44:41.187 (Gateway) Lighting 2 (Vochtigheid border)
2015-07-01 15:44:45.357 (Gateway) Lighting 2 (Vochtigheid border)
2015-07-01 15:44:58.920 Hardware Monitor: Fetching data (System sensors)
2015-07-01 15:45:28.298 MySensors: Node: 3, Sketch Name: Soil Moisture Sensor
2015-07-01 15:45:28.302 MySensors: Node: 3, Sketch Version: 1.0Hooking up the gateway and node to a laptop to use the serial monitor shows data being send from the sensor and received by the gateway.
After plugging in the gateway to my pi running domoticz there was a new hardware detected right away, but only not as a sensor but as a lightning2 type lamp switch which I've named 'vochtigheid border'. The log of this 'switch itself shows:
2015-07-01 15:44:45 On
2015-07-01 15:44:41 Off
2015-07-01 15:41:02 On
2015-07-01 14:49:43 Off
2015-07-01 14:31:56 On
2015-07-01 14:31:56 OffDoes this make any sense to you...?
-
Oh and I'm using this sketc btw : http://www.mysensors.org/build/moisture
-
Hi @Bram81
Looks good so far... i was just about to suggest the domoticz forum, but then i saw this: link text and i guess its you :)In the link (Rain & Moisture scetch) it looks like the GW.present: gw.present(CHILD_ID, S_MOTION);
Does this mean its presented as a motion sensor? @hek ?Anyhow - in the Domoticz code there is not any code for S_MOTION so you have to request this.
MySensorsBase.cppI dont know what happens if you try to present is a humidity sensor? Both humidity and soil is presented as % ??
Br
-
Hi @Bram81
Looks good so far... i was just about to suggest the domoticz forum, but then i saw this: link text and i guess its you :)In the link (Rain & Moisture scetch) it looks like the GW.present: gw.present(CHILD_ID, S_MOTION);
Does this mean its presented as a motion sensor? @hek ?Anyhow - in the Domoticz code there is not any code for S_MOTION so you have to request this.
MySensorsBase.cppI dont know what happens if you try to present is a humidity sensor? Both humidity and soil is presented as % ??
Br
Hi@sundberg84 Yes, that's me.. ;-) I saw that file too, but being still a newbie in Mysensors, Arduino and sketches I didn't really know how to use it. Do I have to put in my libraries folder and add a line #include <filename> in the gateway sketch..?
Right now the sensor is automatically seen as a certain device, within Domoticz there is no way to present it otherwise right?
-
If you mean MySensorsBase.cpp - no thats the domoticz scourscode and you dont use that in the sensor/gateway.
Looking closer at the code shows also your sensors sends V_TRIPPED to domoticz, and thats why you get on/off.I dont know it this works, but i would try to change:
MyMessage msg(CHILD_ID, V_TRIPPED);
to
MyMessage msg(CHILD_ID, V_HUM);and
gw.present(CHILD_ID, S_MOTION);
to
gw.present(CHILD_ID, S_HUM);and upload the scetch to the Moisture sensor again...
It will present the sensor in domoticz as a Humidity sensor but as I said i hope both Moisture and Humidity presents its value from 0-100 %Br
-
Hey, thanks for your help. The sensor presents itself as a Humidity sensor and shows a value of 1% even after adding water to the ground nothing changes, so it seems it's not being updated correctly.
Last week when I was just playing around for the first time with the arduino and sensor used this simple sketch:
int sensorPin = A0; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensorvoid setup() {
// declare the ledPin as an OUTPUT:
Serial.begin(9600);
}void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
delay(1000);
Serial.print("sensor = " );
Serial.println(sensorValue);
}Using the analog output on the sensor and analog0 on the arduino. The values are presented in number between 1-1200 (aprox.)
Even readings in just a number would be fine for me / can be easily transered to a % I guess, where a value of aprox 300 is liquid water and 1050 is the value read when the sensor is in the open air and not sticked in the soil.
Can you think of alike types of sensors with values presented in that range?
-
Hi @Bram81
Yes - the analog is 0 - 1023 and many use it to measure battery %.
This can be converted to % pretty much by dividing it by 10 i thinkint sensorValue = analogRead(sensorPin); Serial.println(sensorValue); sensorValue = sensorValue / 10;You can do much more with upper and lower limits... its just a matter of math and code.
Edit:
This is used in the battery when we want figures from 1.9 (VMIN)-3.3V (VMAX)... maybe it can help you somhow:int Pcnt = static_cast<int>(((Vbat-VMIN)/(VMAX-VMIN))*100.);``` -
Doing some fast math here: Vbat = your analog read value (say 500 as example), VMIN = 300 VMAX = 1023 gives us
500 - 300 / 1023-300 = 200/ 723 = 0,27 = 27% -
Doing some fast math here: Vbat = your analog read value (say 500 as example), VMIN = 300 VMAX = 1023 gives us
500 - 300 / 1023-300 = 200/ 723 = 0,27 = 27%@sundberg84 Hi, I've been trying to modify the sketch

But it gives me errors I cant resolve... Got to a point where the node send back info to the gateway:683
send: 3-3-0-0 s=0,c=1,t=1,pt=2,l=2,st=ok:0
682
send: 3-3-0-0 s=0,c=1,t=1,pt=2,l=2,st=ok:0
683
send: 3-3-0-0 s=0,c=1,t=1,pt=2,l=2,st=ok:0
682
send: 3-3-0-0 s=0,c=1,t=1,pt=2,l=2,st=ok:0Also Domoticz was receiving info, log showed :+1:
2015-07-02 10:31:24.898 (Gateway) Temp + Humidity (TempHum)
2015-07-02 10:31:24.914 (Gateway) Temp + Humidity (TempHum)
2015-07-02 10:31:24.929 (Gateway) Temp + Humidity (TempHum)
2015-07-02 10:31:24.944 (Gateway) Temp + Humidity (TempHum)
2015-07-02 10:31:24.959 (Gateway) Temp + Humidity (TempHum)
2015-07-02 10:31:24.975 (Gateway) Temp + Humidity (TempHum)
2015-07-02 10:31:24.990 (Gateway) Temp + Humidity (TempHum)
2015-07-02 10:31:25.005 (Gateway) Temp + Humidity (TempHum)But still the humidity switch was showing either 0% or 1%.
I guess that is propably because the values must be transfered into % in the sketch, but I am kind of stuck... -
@Bram81
I would try (not at home and cant try):int Analog_Input_Soil_Sensor= A0;
int Analog_Input_Soil_Sensor = 0;as you wrote before, and not #define interrupt analog_input_soil_sensor -2
Also you get only 0 and 1 because this is what you send to the gateway: gw.send(Msg.set(soilva... 0?1:0)
Either you have to define what 0 and 1 is (say dry = 0 moist = 1) or if you want to send it as % use another gw.send code. -
Here is an example of someone build a soil sensor using the light_sensor
http://forum.mysensors.org/topic/1492/soil-moisture-analog-input-question
If you remove the battery code this could be used if you connect to analog pin (Se code below)#include <SPI.h> #include <MySensor.h> #define CHILD_ID_LIGHT 0 #define LIGHT_SENSOR_ANALOG_PIN 1 MySensor gw; MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL); int lastLightLevel; void setup() { gw.begin(); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Soil_Moist_Sensor_grb", "1.15"); // Register all sensors to gateway (they will be created as child devices) gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); } void loop() { int lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23; Serial.println(lightLevel); if (lightLevel != lastLightLevel) { gw.send(msg.set(lightLevel)); lastLightLevel = lightLevel; } }if you want lightlevel in % with a Min and a Max then:
#include <SPI.h> #include <MySensor.h> #define CHILD_ID_LIGHT 0 #define LIGHT_SENSOR_ANALOG_PIN 1 #define MIN 300 // Liquid #define MAX 1023 // Air MySensor gw; MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL); int lastLightLevel; void setup() { gw.begin(); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Soil_Moist_Sensor_grb", "1.15"); // Register all sensors to gateway (they will be created as child devices) gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); } void loop() { int lightLevel = static_cast<int>(((analogRead(LIGHT_SENSOR_ANALOG_PIN)-MIN)/(MAX-MIN))*100.); Serial.println(lightLevel); if (lightLevel != lastLightLevel) { gw.send(msg.set(lightLevel)); lastLightLevel = lightLevel; } }I have read some more...
About the digital pin and use (as you mentioned at first... )
It looks like there is a switch/nob on the hardware you can turn.
This will set the trigger point between dry and moist and send 1 or 0.
I think thats why the scetches was using S_Motion... either its dry (untriggered) or wet (triggered).
I dont know how to program or wire this though...Best of luck :) Hope i didnt just complicate things...
-
Here is an example of someone build a soil sensor using the light_sensor
http://forum.mysensors.org/topic/1492/soil-moisture-analog-input-question
If you remove the battery code this could be used if you connect to analog pin (Se code below)#include <SPI.h> #include <MySensor.h> #define CHILD_ID_LIGHT 0 #define LIGHT_SENSOR_ANALOG_PIN 1 MySensor gw; MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL); int lastLightLevel; void setup() { gw.begin(); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Soil_Moist_Sensor_grb", "1.15"); // Register all sensors to gateway (they will be created as child devices) gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); } void loop() { int lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23; Serial.println(lightLevel); if (lightLevel != lastLightLevel) { gw.send(msg.set(lightLevel)); lastLightLevel = lightLevel; } }if you want lightlevel in % with a Min and a Max then:
#include <SPI.h> #include <MySensor.h> #define CHILD_ID_LIGHT 0 #define LIGHT_SENSOR_ANALOG_PIN 1 #define MIN 300 // Liquid #define MAX 1023 // Air MySensor gw; MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL); int lastLightLevel; void setup() { gw.begin(); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Soil_Moist_Sensor_grb", "1.15"); // Register all sensors to gateway (they will be created as child devices) gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); } void loop() { int lightLevel = static_cast<int>(((analogRead(LIGHT_SENSOR_ANALOG_PIN)-MIN)/(MAX-MIN))*100.); Serial.println(lightLevel); if (lightLevel != lastLightLevel) { gw.send(msg.set(lightLevel)); lastLightLevel = lightLevel; } }I have read some more...
About the digital pin and use (as you mentioned at first... )
It looks like there is a switch/nob on the hardware you can turn.
This will set the trigger point between dry and moist and send 1 or 0.
I think thats why the scetches was using S_Motion... either its dry (untriggered) or wet (triggered).
I dont know how to program or wire this though...Best of luck :) Hope i didnt just complicate things...
@sundberg84 Hey! Thank you verry much for your help and suggestions!!
I actually got it working combining your sketch witch my simple one resulting in this:#include <SPI.h>
#include <MySensor.h>#define CHILD_ID_LIGHT 0
#define LIGHT_SENSOR_ANALOG_PIN 1
#define MIN 300 // Liquid
#define MAX 1023 // Airint sensorPin = A0; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensorMySensor gw;
MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
int lastLightLevel;void setup(){
Serial.begin(9600);
gw.begin();
// Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Soil_Moist_Sensor_grb", "1.15");// Register all sensors to gateway (they will be created as child devices)
gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
}void loop(){
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
delay(1000);
Serial.print("sensor = " );
Serial.println(sensorValue);
gw.send(msg.set(sensorValue));
}The sensor shows up in Domoticz as a light sensor meassuring in lux, but the numbers do match the output of the sensor.
Another thing is that after about 15 min the gateway started functioning. Seems like a problem that I had last week returned...
Loading the board with the pingpongtest shows that suddenly my radio chip is recognized as NRF24L01 instead of the + version, although the label on te chips shows NRF24L01+
Changing radios doesn't help, I'm completely in the dark... maybe just shitty radios..?