Opinions on Arduino based cable connection
Moderator: leecollings
-
- Posts: 331
- Joined: Monday 03 July 2017 19:58
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Opinions on Arduino based cable connection
Hi all,
Planning a Domoticz installation on Raspberry Pi. For sensors, i have cabled reed switches and cabled PIRs. What i am planning is to collect all sensor cables to an Arduino Mega IO, and send all switch status from the Arduino to Rpi from ethernet shield. I have no intention of using wireless in any sensors or Domoticz connections. So;
May i get your suggestions on the protocol for the Arduino Mega+ Ethernet Shield to Raspberry Pi connection? Should i use direct JSON calls from arduino to domoticz, or should i use MQTT or anything else? Which would be the more efficient way? As i understand from mysensors, it is mainly for wireless sensors. What would be the way to go for wired sensors?
Planning a Domoticz installation on Raspberry Pi. For sensors, i have cabled reed switches and cabled PIRs. What i am planning is to collect all sensor cables to an Arduino Mega IO, and send all switch status from the Arduino to Rpi from ethernet shield. I have no intention of using wireless in any sensors or Domoticz connections. So;
May i get your suggestions on the protocol for the Arduino Mega+ Ethernet Shield to Raspberry Pi connection? Should i use direct JSON calls from arduino to domoticz, or should i use MQTT or anything else? Which would be the more efficient way? As i understand from mysensors, it is mainly for wireless sensors. What would be the way to go for wired sensors?
-
- Posts: 536
- Joined: Friday 23 December 2016 16:40
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Stable
- Location: Netherlands Purmerend
- Contact:
Re: Opinions on Arduino based cable connection
EASY ESP ?
Exactly as you wanted only not an ethernetshield but Wifi instead and no programming skills required.
I have several ones and one with 4 sensors connected to my domotics.
https://www.letscontrolit.com/
Exactly as you wanted only not an ethernetshield but Wifi instead and no programming skills required.
I have several ones and one with 4 sensors connected to my domotics.
https://www.letscontrolit.com/
-
- Posts: 331
- Joined: Monday 03 July 2017 19:58
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: Opinions on Arduino based cable connection
Thanks frejin,freijn wrote: ↑Saturday 14 October 2017 19:28 EASY ESP ?
Exactly as you wanted only not an ethernetshield but Wifi instead and no programming skills required.
I have several ones and one with 4 sensors connected to my domotics.
https://www.letscontrolit.com/
i checked it out; looks great. However, any wireless protocol is not wanted specifically. The cables for the sensors in the house are already laid out and it is specifically wanted that these cables are to be used. As i understand from Easy ESP it is wifi connected with ESP8266. So, unfortunately it won't be of use for me in this project, but it is great for my own usage in other projects, i will try it. Thanks again...
-
- Posts: 536
- Joined: Friday 23 December 2016 16:40
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Stable
- Location: Netherlands Purmerend
- Contact:
Re: Opinions on Arduino based cable connection
aha,
understand your goal..
Perhaps.. as the sources are available you can use that to rewrite from wifi to serial communication ?
understand your goal..
Perhaps.. as the sources are available you can use that to rewrite from wifi to serial communication ?
- bbqkees
- Posts: 407
- Joined: Sunday 17 August 2014 21:01
- Target OS: Linux
- Domoticz version: 4.1x
- Location: The Netherlands
- Contact:
Re: Opinions on Arduino based cable connection
I have several Arduino's with Ethernet connected to Domoticz.
One reads my electricity meter, one my boiler, one another controller and there are 3 others used for sensors/actuators.
All of them work with JSON GET requests, but I am am going to reprogram one of them for MQTT to test the difference.
The problem I have with JSON is that although sending data from the Arduino to Domoticz works fine every time, sending a command back to the Arduino from Domoticz is not fail safe in my case.
In my opinion MQTT is not really superior to JSON.
MQTT does have more overhead than a simple GET request with JSON.
The major benefit of MQTT is that it is not specific to Domoticz.
So if you create a MQTT device it can interact with many systems, whereas the JSON type is fixed to Domoticz.
My advice would also be to stick with the Wiznet ethernet shields, these have the best compatibility with Arduino.
One reads my electricity meter, one my boiler, one another controller and there are 3 others used for sensors/actuators.
All of them work with JSON GET requests, but I am am going to reprogram one of them for MQTT to test the difference.
The problem I have with JSON is that although sending data from the Arduino to Domoticz works fine every time, sending a command back to the Arduino from Domoticz is not fail safe in my case.
In my opinion MQTT is not really superior to JSON.
MQTT does have more overhead than a simple GET request with JSON.
The major benefit of MQTT is that it is not specific to Domoticz.
So if you create a MQTT device it can interact with many systems, whereas the JSON type is fixed to Domoticz.
My advice would also be to stick with the Wiznet ethernet shields, these have the best compatibility with Arduino.
Bosch / Nefit / Buderus / Junkers / Worcester / Sieger EMS bus Wi-Fi MQTT Gateway and interface boards: https://bbqkees-electronics.nl/
-
- Posts: 331
- Joined: Monday 03 July 2017 19:58
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: Opinions on Arduino based cable connection
Hi bbqkees, is it possible if you can send sample arduino sketches with the JSON calls? Thanks...bbqkees wrote: ↑Monday 16 October 2017 11:25 I have several Arduino's with Ethernet connected to Domoticz.
One reads my electricity meter, one my boiler, one another controller and there are 3 others used for sensors/actuators.
All of them work with JSON GET requests, but I am am going to reprogram one of them for MQTT to test the difference.
The problem I have with JSON is that although sending data from the Arduino to Domoticz works fine every time, sending a command back to the Arduino from Domoticz is not fail safe in my case.
In my opinion MQTT is not really superior to JSON.
MQTT does have more overhead than a simple GET request with JSON.
The major benefit of MQTT is that it is not specific to Domoticz.
So if you create a MQTT device it can interact with many systems, whereas the JSON type is fixed to Domoticz.
My advice would also be to stick with the Wiznet ethernet shields, these have the best compatibility with Arduino.
- bbqkees
- Posts: 407
- Joined: Sunday 17 August 2014 21:01
- Target OS: Linux
- Domoticz version: 4.1x
- Location: The Netherlands
- Contact:
Re: Opinions on Arduino based cable connection
See my Github page.
Bosch / Nefit / Buderus / Junkers / Worcester / Sieger EMS bus Wi-Fi MQTT Gateway and interface boards: https://bbqkees-electronics.nl/
- ILoveIOT
- Posts: 59
- Joined: Sunday 25 March 2018 17:47
- Target OS: Linux
- Domoticz version: 2020.2
- Location: NL
- Contact:
Re: Opinions on Arduino based cable connection
There is a plugin available for the Nodo-Mega V3.7, with nodo shield and Ethernet shield, I use it for many years.
http://www.nodo-domotica.nl/forum/viewt ... 120#p15109
The forum is dutch, not sure how google translate will solve it, and they stopped working on it.
http://www.nodo-domotica.nl/forum/viewt ... 120#p15109
The forum is dutch, not sure how google translate will solve it, and they stopped working on it.
1x OPI PC 5.8.16 Debian 10, MiniDNLA,SMD230,EpEver,MPD,800GB,Wiegand,7 temps,DHT,32/64 I/O,2022.1
2x OPI PC 4.19.25 Debian 9, MPD,7 temps,16/32 I/O,BMP,4.10717
1x IntelNUC 5.10 Debian 10, 2TB,DalyBMS,2023.1
3x ESPEasy NodeMCU V3, 16/16 I/O
2x OPI PC 4.19.25 Debian 9, MPD,7 temps,16/32 I/O,BMP,4.10717
1x IntelNUC 5.10 Debian 10, 2TB,DalyBMS,2023.1
3x ESPEasy NodeMCU V3, 16/16 I/O
-
- Posts: 331
- Joined: Monday 03 July 2017 19:58
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: Opinions on Arduino based cable connection
In the end i managed to do it. Connected a total of 24 reed and PIR sensors to an arduino mega. The arduino reads on/off status of the sensors with GPIO ports and sends to domoticz with json calls. Since some of the sensor cables are long, the they required an optocoupler before connecting to the GPIO ports; because of the length related noise on the cables. The sensors were sending nanosecond on/off signals before the optocouplers.
For the lights, another arduino mega is used (a total of 20 lights, cable connection again). This time i used mysensors, stripping out the wireless parts in the .ino. Works perfectly so far. Anyone needing the .ino files and details, just ask for it...
For the lights, another arduino mega is used (a total of 20 lights, cable connection again). This time i used mysensors, stripping out the wireless parts in the .ino. Works perfectly so far. Anyone needing the .ino files and details, just ask for it...
-
- Posts: 229
- Joined: Wednesday 30 April 2014 20:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Stable
- Location: The Netherlands
- Contact:
Re: Opinions on Arduino based cable connection
Hello febalci,
I'am interested and need some help. I want to start simple. What do I want to achieve first?
Code: Select all
doorcontact >>>>>>
<---> Arduino nano <-> ethernet (ENC28J60) <-----------------------> Domoticz
relay <<<<<<
Thanks in advance.
Jan
-
- Posts: 331
- Joined: Monday 03 July 2017 19:58
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: Opinions on Arduino based cable connection
Hello Jen,Jan Jansen wrote: ↑Monday 24 September 2018 15:28Hello febalci,
I'am interested and need some help. I want to start simple. What do I want to achieve first?
I'am interested in your ino (s). What else is necessary on the side of Domoticz?Code: Select all
doorcontact >>>>>> <---> Arduino nano <-> ethernet (ENC28J60) <-----------------------> Domoticz relay <<<<<<
Thanks in advance.
Jan
First you need to make hardware connection of doorcontacts to arduino. Prefer digital pins and don't forget to put resistors. You can find info on this on the internet.
Then you have to create Dummy Switch devices in Domoticz, one per doorcontact.
On Arduino i used this .ino (For 24 door contacts and PIR sensors):
Code: Select all
// ALARM DOMOTICZ Connection
// 09.11.2017, v4.0
// SPI and Ethernet is needed for Ethernet shield
#include <SPI.h>
#include <Ethernet.h>
//DEBUG 1 Sends output to SerialPort
#define DEBUG 1
#define OPEN 1 // HIGH
#define CLOSED 0 // LOW
#define UNKNOWN 2 // --- reset / force update
//INPUT PIN Numbers on Arduino
#define PIN_MUTFAK_SU 4
#define PIN_EBEVEYN_BANYO_SU 6
#define PIN_BANYO_SU 8
#define PIN_PANO_ISI_DUMAN 10
#define PIN_OTURMA_PEN_MK 12
#define PIN_SALON_KPEN_MK 14
#define PIN_SALON_BPEN_1_MK 16
#define PIN_SALON_BPEN_2_MK 18
#define PIN_BALKON_PEN_1_MK 20
#define PIN_BALKON_PEN_2_MK 22
#define PIN_MUTFAK_PEN_MK 24
#define PIN_EBEVEYN_PEN_A_MK 26
#define PIN_EBEVEYN_PEN_G_MK 28
#define PIN_COCUK_MK 30
#define PIN_GIRISKAPI_MK 32
#define PIN_OTURMA_PIR 34
#define PIN_SALON_PIR 36
#define PIN_BALKON_PIR 38
#define PIN_MUTFAK_PIR 40
#define PIN_EBEVEYN_PIR 42
#define PIN_EBEVEYN_BANYO_PIR 44
#define PIN_COCUK_PIR 46
#define PIN_KORIDOR_PIR 48
#define PIN_BUYUK_BANYO_PIR 50
// Last Statuıs of the Sensors
int MUTFAK_SUStatus = UNKNOWN;
int EBEVEYN_BANYO_SUStatus = UNKNOWN;
int BANYO_SUStatus = UNKNOWN;
int PANO_ISI_DUMANStatus = UNKNOWN;
int OTURMA_PEN_MKStatus = UNKNOWN;
int SALON_KPEN_MKStatus = UNKNOWN;
int SALON_BPEN_1_MKStatus = UNKNOWN;
int SALON_BPEN_2_MKStatus = UNKNOWN;
int BALKON_PEN_1_MKStatus = UNKNOWN;
int BALKON_PEN_2_MKStatus = UNKNOWN;
int MUTFAK_PEN_MKStatus = UNKNOWN;
int EBEVEYN_PEN_A_MKStatus = UNKNOWN;
int EBEVEYN_PEN_G_MKStatus = UNKNOWN;
int COCUK_MKStatus = UNKNOWN;
int GIRISKAPI_MKStatus = UNKNOWN;
int OTURMA_PIRStatus = UNKNOWN;
int SALON_PIRStatus = UNKNOWN;
int BALKON_PIRStatus = UNKNOWN;
int MUTFAK_PIRStatus = UNKNOWN;
int EBEVEYN_PIRStatus = UNKNOWN;
int EBEVEYN_BANYO_PIRStatus = UNKNOWN;
int COCUK_PIRStatus = UNKNOWN;
int KORIDOR_PIRStatus = UNKNOWN;
int BUYUK_BANYO_PIRStatus = UNKNOWN;
// IDX numbers of PIR and Magnetc Contacts on Domoticz-Devices Page
int IDX_MUTFAK_SU = 31;
int IDX_EBEVEYN_BANYO_SU = 30;
int IDX_BANYO_SU = 29;
int IDX_PANO_ISI_DUMAN = 32;
int IDX_OTURMA_PEN_MK = 6;
int IDX_SALON_KPEN_MK = 7;
int IDX_SALON_BPEN_1_MK = 8;
int IDX_SALON_BPEN_2_MK = 9;
int IDX_BALKON_PEN_1_MK = 11;
int IDX_BALKON_PEN_2_MK = 10;
int IDX_MUTFAK_PEN_MK = 12;
int IDX_EBEVEYN_PEN_A_MK = 13;
int IDX_EBEVEYN_PEN_G_MK = 14;
int IDX_COCUK_MK = 15;
int IDX_GIRISKAPI_MK = 16;
int IDX_OTURMA_PIR = 17;
int IDX_SALON_PIR = 18;
int IDX_BALKON_PIR = 25;
int IDX_MUTFAK_PIR = 22;
int IDX_EBEVEYN_PIR = 23;
int IDX_EBEVEYN_BANYO_PIR = 21;
int IDX_COCUK_PIR = 24;
int IDX_KORIDOR_PIR = 19;
int IDX_BUYUK_BANYO_PIR = 20;
// Arduino MAC ve IP addresses
byte mac[] = {
0xDE, 0xAD, 0xBE, 0x30, 0x39, 0x01};//Random address
IPAddress ip(192,168,31,40); //IP Address of Arduino
IPAddress domoticz(192,168,31,20); // Domoticz IP Address
int port = 8080; // Domoticz Port No
EthernetClient client;
//httprequest functions, sends status info to Domoticz
// /json.htm?type=command¶m=switchlight&idx=XX&switchcmd=On
void httpRequestswitch(int IDX, String status) {
// When the connection is successful:
if (client.connect(domoticz, port)) {
#if DEBUG
Serial.print("GET /json.htm?type=command¶m=switchlight&idx=");
Serial.print(IDX);
Serial.print("&switchcmd=");
Serial.println(status);
#endif
client.print( "GET /json.htm?type=command¶m=switchlight&idx=");
client.print(IDX);
client.print("&switchcmd=");
client.print(status);
client.println( " HTTP/1.1");
client.print( "Host: ");
client.println(ip);
client.println( "Connection: close");
client.println();
client.println();
client.stop();
delay(150);
}
else {
client.stop();
}
}
void httpRequestvalue(int IDX, float value) {
if (client.connect(domoticz, port)) {
// When the connection is successful:
#if DEBUG
Serial.print("GET /json.htm?type=command¶m=udevice&idx=");
Serial.print(IDX);
Serial.print("&nvalue=0&svalue=");
Serial.println(value,1);
#endif
client.print( "GET /json.htm?type=command¶m=udevice&idx=");
client.print(IDX);
client.print("&nvalue=0&svalue=");
client.print(value,1);
client.println( " HTTP/1.1");
client.print( "Host: ");
client.println(ip);
client.println( "Connection: close");
client.println();
client.println();
client.stop();
delay(150);
}
else {
client.stop();
}
}
int contactState(int pin)
{
// LOW -> CLOSED
// HIGH -> OPEN
return (digitalRead(pin) == HIGH)?OPEN:CLOSED;
}
void updateContactStatus()
{
int currentStatus;
const char* msg = NULL;
currentStatus = contactState(PIN_MUTFAK_SU);
if (MUTFAK_SUStatus != currentStatus)
{
MUTFAK_SUStatus = currentStatus;
if(MUTFAK_SUStatus == CLOSED) msg = "Off";
else msg = "On";
httpRequestswitch(IDX_MUTFAK_SU, msg);
return; // only one message per loop
}
currentStatus = contactState(PIN_EBEVEYN_BANYO_SU);
if (EBEVEYN_BANYO_SUStatus != currentStatus)
{
EBEVEYN_BANYO_SUStatus = currentStatus;
if(EBEVEYN_BANYO_SUStatus == CLOSED) msg = "Off";
else msg = "On";
httpRequestswitch(IDX_EBEVEYN_BANYO_SU, msg);
return; // only one message per loop
}
currentStatus = contactState(PIN_BANYO_SU);
if (BANYO_SUStatus != currentStatus)
{
BANYO_SUStatus = currentStatus;
if(BANYO_SUStatus == CLOSED) msg = "Off";
else msg = "On";
httpRequestswitch(IDX_BANYO_SU, msg);
return; // only one message per loop
}
currentStatus = contactState(PIN_PANO_ISI_DUMAN);
if (PANO_ISI_DUMANStatus != currentStatus)
{
PANO_ISI_DUMANStatus = currentStatus;
if(PANO_ISI_DUMANStatus == CLOSED) msg = "Off";
else msg = "On";
httpRequestswitch(IDX_PANO_ISI_DUMAN, msg);
return; // only one message per loop
}
currentStatus = contactState(PIN_OTURMA_PEN_MK);
if (OTURMA_PEN_MKStatus != currentStatus)
{
OTURMA_PEN_MKStatus = currentStatus;
if(OTURMA_PEN_MKStatus == CLOSED) msg = "Off";
else msg = "On";
httpRequestswitch(IDX_OTURMA_PEN_MK, msg);
return; // only one message per loop
}
currentStatus = contactState(PIN_SALON_KPEN_MK);
if (SALON_KPEN_MKStatus != currentStatus)
{
SALON_KPEN_MKStatus = currentStatus;
if(SALON_KPEN_MKStatus == CLOSED) msg = "Off";
else msg = "On";
httpRequestswitch(IDX_SALON_KPEN_MK, msg);
return; // only one message per loop
}
currentStatus = contactState(PIN_SALON_BPEN_1_MK);
if (SALON_BPEN_1_MKStatus != currentStatus)
{
SALON_BPEN_1_MKStatus = currentStatus;
if(SALON_BPEN_1_MKStatus == CLOSED) msg = "Off";
else msg = "On";
httpRequestswitch(IDX_SALON_BPEN_1_MK, msg);
return; // only one message per loop
}
currentStatus = contactState(PIN_SALON_BPEN_2_MK);
if (SALON_BPEN_2_MKStatus != currentStatus)
{
SALON_BPEN_2_MKStatus = currentStatus;
if(SALON_BPEN_2_MKStatus == CLOSED) msg = "Off";
else msg = "On";
httpRequestswitch(IDX_SALON_BPEN_2_MK, msg);
return; // only one message per loop
}
currentStatus = contactState(PIN_BALKON_PEN_1_MK);
if (BALKON_PEN_1_MKStatus != currentStatus)
{
BALKON_PEN_1_MKStatus = currentStatus;
if(BALKON_PEN_1_MKStatus == CLOSED) msg = "Off";
else msg = "On";
httpRequestswitch(IDX_BALKON_PEN_1_MK, msg);
return; // only one message per loop
}
currentStatus = contactState(PIN_BALKON_PEN_2_MK);
if (BALKON_PEN_2_MKStatus != currentStatus)
{
BALKON_PEN_2_MKStatus = currentStatus;
if(BALKON_PEN_2_MKStatus == CLOSED) msg = "Off";
else msg = "On";
httpRequestswitch(IDX_BALKON_PEN_2_MK, msg);
return; // only one message per loop
}
currentStatus = contactState(PIN_MUTFAK_PEN_MK);
if (MUTFAK_PEN_MKStatus != currentStatus)
{
MUTFAK_PEN_MKStatus = currentStatus;
if(MUTFAK_PEN_MKStatus == CLOSED) msg = "Off";
else msg = "On";
httpRequestswitch(IDX_MUTFAK_PEN_MK, msg);
return; // only one message per loop
}
currentStatus = contactState(PIN_EBEVEYN_PEN_A_MK);
if (EBEVEYN_PEN_A_MKStatus != currentStatus)
{
EBEVEYN_PEN_A_MKStatus = currentStatus;
if(EBEVEYN_PEN_A_MKStatus == CLOSED) msg = "Off";
else msg = "On";
httpRequestswitch(IDX_EBEVEYN_PEN_A_MK, msg);
return; // only one message per loop
}
currentStatus = contactState(PIN_EBEVEYN_PEN_G_MK);
if (EBEVEYN_PEN_G_MKStatus != currentStatus)
{
EBEVEYN_PEN_G_MKStatus = currentStatus;
if(EBEVEYN_PEN_G_MKStatus == CLOSED) msg = "Off";
else msg = "On";
httpRequestswitch(IDX_EBEVEYN_PEN_G_MK, msg);
return; // only one message per loop
}
currentStatus = contactState(PIN_COCUK_MK);
if (COCUK_MKStatus != currentStatus)
{
COCUK_MKStatus = currentStatus;
if(COCUK_MKStatus == CLOSED) msg = "Off";
else msg = "On";
httpRequestswitch(IDX_COCUK_MK, msg);
return; // only one message per loop
}
currentStatus = contactState(PIN_GIRISKAPI_MK);
if (GIRISKAPI_MKStatus != currentStatus)
{
GIRISKAPI_MKStatus = currentStatus;
if(GIRISKAPI_MKStatus == CLOSED) msg = "Off";
else msg = "On";
httpRequestswitch(IDX_GIRISKAPI_MK, msg);
return; // only one message per loop
}
currentStatus = contactState(PIN_OTURMA_PIR);
if (OTURMA_PIRStatus != currentStatus)
{
OTURMA_PIRStatus = currentStatus;
if(OTURMA_PIRStatus == CLOSED) msg = "Off";
else msg = "On";
httpRequestswitch(IDX_OTURMA_PIR, msg);
return; // only one message per loop
}
currentStatus = contactState(PIN_SALON_PIR);
if (SALON_PIRStatus != currentStatus)
{
SALON_PIRStatus = currentStatus;
if(SALON_PIRStatus == CLOSED) msg = "Off";
else msg = "On";
httpRequestswitch(IDX_SALON_PIR, msg);
return; // only one message per loop
}
currentStatus = contactState(PIN_BALKON_PIR);
if (BALKON_PIRStatus != currentStatus)
{
BALKON_PIRStatus = currentStatus;
if(BALKON_PIRStatus == CLOSED) msg = "Off";
else msg = "On";
httpRequestswitch(IDX_BALKON_PIR, msg);
return; // only one message per loop
}
currentStatus = contactState(PIN_MUTFAK_PIR);
if (MUTFAK_PIRStatus != currentStatus)
{
MUTFAK_PIRStatus = currentStatus;
if(MUTFAK_PIRStatus == CLOSED) msg = "Off";
else msg = "On";
httpRequestswitch(IDX_MUTFAK_PIR, msg);
return; // only one message per loop
}
currentStatus = contactState(PIN_EBEVEYN_PIR);
if (EBEVEYN_PIRStatus != currentStatus)
{
EBEVEYN_PIRStatus = currentStatus;
if(EBEVEYN_PIRStatus == CLOSED) msg = "Off";
else msg = "On";
httpRequestswitch(IDX_EBEVEYN_PIR, msg);
return; // only one message per loop
}
currentStatus = contactState(PIN_EBEVEYN_BANYO_PIR);
if (EBEVEYN_BANYO_PIRStatus != currentStatus)
{
EBEVEYN_BANYO_PIRStatus = currentStatus;
if(EBEVEYN_BANYO_PIRStatus == CLOSED) msg = "Off";
else msg = "On";
httpRequestswitch(IDX_EBEVEYN_BANYO_PIR, msg);
return; // only one message per loop
}
currentStatus = contactState(PIN_COCUK_PIR);
if (COCUK_PIRStatus != currentStatus)
{
COCUK_PIRStatus = currentStatus;
if(COCUK_PIRStatus == CLOSED) msg = "Off";
else msg = "On";
httpRequestswitch(IDX_COCUK_PIR, msg);
return; // only one message per loop
}
currentStatus = contactState(PIN_KORIDOR_PIR);
if (KORIDOR_PIRStatus != currentStatus)
{
KORIDOR_PIRStatus = currentStatus;
if(KORIDOR_PIRStatus == CLOSED) msg = "Off";
else msg = "On";
httpRequestswitch(IDX_KORIDOR_PIR, msg);
return; // only one message per loop
}
currentStatus = contactState(PIN_BUYUK_BANYO_PIR);
if (BUYUK_BANYO_PIRStatus != currentStatus)
{
BUYUK_BANYO_PIRStatus = currentStatus;
if(BUYUK_BANYO_PIRStatus == CLOSED) msg = "Off";
else msg = "On";
httpRequestswitch(IDX_BUYUK_BANYO_PIR, msg);
return; // only one message per loop
}
}
void setup() {
pinMode(PIN_MUTFAK_SU , INPUT);
pinMode(PIN_EBEVEYN_BANYO_SU , INPUT);
pinMode(PIN_BANYO_SU , INPUT);
pinMode(PIN_PANO_ISI_DUMAN , INPUT);
pinMode(PIN_OTURMA_PEN_MK , INPUT);
pinMode(PIN_SALON_KPEN_MK , INPUT);
pinMode(PIN_SALON_BPEN_1_MK , INPUT);
pinMode(PIN_SALON_BPEN_2_MK , INPUT);
pinMode(PIN_BALKON_PEN_1_MK , INPUT);
pinMode(PIN_BALKON_PEN_2_MK , INPUT);
pinMode(PIN_MUTFAK_PEN_MK , INPUT);
pinMode(PIN_EBEVEYN_PEN_A_MK , INPUT);
pinMode(PIN_EBEVEYN_PEN_G_MK , INPUT);
pinMode(PIN_COCUK_MK , INPUT);
pinMode(PIN_GIRISKAPI_MK , INPUT);
pinMode(PIN_OTURMA_PIR , INPUT);
pinMode(PIN_SALON_PIR , INPUT);
pinMode(PIN_BALKON_PIR , INPUT);
pinMode(PIN_MUTFAK_PIR , INPUT);
pinMode(PIN_EBEVEYN_PIR , INPUT);
pinMode(PIN_EBEVEYN_BANYO_PIR , INPUT);
pinMode(PIN_COCUK_PIR , INPUT);
pinMode(PIN_KORIDOR_PIR , INPUT);
pinMode(PIN_BUYUK_BANYO_PIR , INPUT);
#if DEBUG
Serial.begin(9600);
Serial.println("Arduino Alarm - Domoticz Connection");
#endif
Ethernet.begin(mac, ip);
#if DEBUG
Serial.print("Arduino IP addresss: ");
delay(1000);
Serial.println(ip);
#endif
}
void loop()
{
updateContactStatus();
}
Btw i didn't get the usage of relay in your assumption. Door contacts are only one side status devices. And this .ino is working like a Security Alarm. The status is sent only one way to Domoticz. Good Luck.
-
- Posts: 543
- Joined: Saturday 02 July 2016 5:17
- Target OS: Linux
- Domoticz version: Beta
- Contact:
Re: Opinions on Arduino based cable connection
You don't need an arduino for reed switches, it can be done very easily with just a Raspberry Pi.
See: viewtopic.php?f=65&t=24991&p=192239#p192239
I've got a Pi 3 B+ which only monitors a reed switch working very nicely.
See: viewtopic.php?f=65&t=24991&p=192239#p192239
I've got a Pi 3 B+ which only monitors a reed switch working very nicely.
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
-
- Posts: 229
- Joined: Wednesday 30 April 2014 20:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Stable
- Location: The Netherlands
- Contact:
Re: Opinions on Arduino based cable connection
Thanks for the answers.
@febalci: I will try. At the moment I do not need it immediately because I use a few pifaces. I just want to learn how to connect an arduino with connected sensors and actuators via Ethernet to Domoticz. I think I'am a step further.
Jan
@febalci: I will try. At the moment I do not need it immediately because I use a few pifaces. I just want to learn how to connect an arduino with connected sensors and actuators via Ethernet to Domoticz. I think I'am a step further.
Jan
-
- Posts: 132
- Joined: Tuesday 14 January 2014 0:03
- Target OS: Linux
- Domoticz version:
- Contact:
Re: Opinions on Arduino based cable connection
Hi Febalci,
just used your code for Arduino, I have edited the file to suit my needs i.e. IP address, ports etc.
I have commented out nearly all the inputs apart from the 1st one
#define PIN_MUTFAK_SU 4
int MUTFAK_SUStatus = UNKNOWN;
int IDX_MUTFAK_SU = 44;
Anything related to MUTFAK_SU I have left in every other device I have commented out.
I created a dummy switch in Domoticz and in SETUP/HARDWARE it has an IDX of 44 however in setup devices
517 MUTFAK_SU 00014255 1 MUTFAK_SU Light/Switch Switch Off
I have swapped between 517 and 44 no difference.
I have wired the switch as per the diagram attached but to pin 4
if I run serial monitor I can see the switch turning on and off although it switches on/off /on/off when switched
but I still see nothing in Domoticz nothing in the log, although my Domoticz does require a password i'm not even getting a failed to connect or similar.
Any ideas will be greatly appreciated as this is exactly what I am looking for.
I have a hardwired alarm system and can use the existing devices to control scenes.
cheers
just used your code for Arduino, I have edited the file to suit my needs i.e. IP address, ports etc.
I have commented out nearly all the inputs apart from the 1st one
#define PIN_MUTFAK_SU 4
int MUTFAK_SUStatus = UNKNOWN;
int IDX_MUTFAK_SU = 44;
Anything related to MUTFAK_SU I have left in every other device I have commented out.
I created a dummy switch in Domoticz and in SETUP/HARDWARE it has an IDX of 44 however in setup devices
517 MUTFAK_SU 00014255 1 MUTFAK_SU Light/Switch Switch Off
I have swapped between 517 and 44 no difference.
I have wired the switch as per the diagram attached but to pin 4
if I run serial monitor I can see the switch turning on and off although it switches on/off /on/off when switched
but I still see nothing in Domoticz nothing in the log, although my Domoticz does require a password i'm not even getting a failed to connect or similar.
Any ideas will be greatly appreciated as this is exactly what I am looking for.
I have a hardwired alarm system and can use the existing devices to control scenes.
cheers
- Attachments
-
- switch.png (130.46 KiB) Viewed 4399 times
-
- Posts: 331
- Joined: Monday 03 July 2017 19:58
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: Opinions on Arduino based cable connection
Dear alarmguy,alarm_guy1 wrote: ↑Tuesday 12 March 2019 15:53
if I run serial monitor I can see the switch turning on and off although it switches on/off /on/off when switched
but I still see nothing in Domoticz nothing in the log, although my Domoticz does require a password i'm not even getting a failed to connect or similar.
Any ideas will be greatly appreciated as this is exactly what I am looking for.
I have a hardwired alarm system and can use the existing devices to control scenes.
cheers
the IDX you should be using in the .ino is in the Setup/Devices Page. So, you should use 517, not 44... In case there might be some typo or something i post you here the 1 input code. Please use this .ino:
Code: Select all
// SPI and Ethernet is needed for Ethernet shield
#include <SPI.h>
#include <Ethernet.h>
//DEBUG 1 Sends output to SerialPort
#define DEBUG 1
#define OPEN 1 // HIGH
#define CLOSED 0 // LOW
#define UNKNOWN 2 // --- reset / force update
//INPUT PIN Numbers on Arduino
#define PIN_MUTFAK_SU 517
// Last Status of the Sensors
int MUTFAK_SUStatus = UNKNOWN;
// IDX numbers of PIR and Reed Contacts on Domoticz-Devices Page
int IDX_MUTFAK_SU = 31;
// Arduino MAC ve IP addresses
byte mac[] = {
0xDE, 0xAD, 0xBE, 0x30, 0x39, 0x01};//Random address
IPAddress ip(192,168,31,40); //IP Address of Arduino
IPAddress domoticz(192,168,31,20); // Domoticz IP Address
int port = 8080; // Domoticz Port No
EthernetClient client;
//httprequest functions, sends status info to Domoticz
// /json.htm?type=command¶m=switchlight&idx=XX&switchcmd=On
void httpRequestswitch(int IDX, String status) {
// When the connection is successful:
if (client.connect(domoticz, port)) {
#if DEBUG
Serial.print("GET /json.htm?type=command¶m=switchlight&idx=");
Serial.print(IDX);
Serial.print("&switchcmd=");
Serial.println(status);
#endif
client.print( "GET /json.htm?type=command¶m=switchlight&idx=");
client.print(IDX);
client.print("&switchcmd=");
client.print(status);
client.println( " HTTP/1.1");
client.print( "Host: ");
client.println(ip);
client.println( "Connection: close");
client.println();
client.println();
client.stop();
delay(150);
}
else {
client.stop();
}
}
int contactState(int pin)
{
// LOW -> CLOSED
// HIGH -> OPEN
return (digitalRead(pin) == HIGH)?OPEN:CLOSED;
}
void updateContactStatus()
{
int currentStatus;
const char* msg = NULL;
currentStatus = contactState(PIN_MUTFAK_SU);
if (MUTFAK_SUStatus != currentStatus)
{
MUTFAK_SUStatus = currentStatus;
if(MUTFAK_SUStatus == CLOSED) msg = "Off";
else msg = "On";
httpRequestswitch(IDX_MUTFAK_SU, msg);
return; // only one message per loop
}
}
void setup() {
pinMode(PIN_MUTFAK_SU , INPUT);
#if DEBUG
Serial.begin(9600);
Serial.println("Arduino Alarm - Domoticz Connection");
#endif
Ethernet.begin(mac, ip);
#if DEBUG
Serial.print("Arduino IP addresss: ");
delay(1000);
Serial.println(ip);
#endif
}
void loop()
{
updateContactStatus();
}
-
- Posts: 132
- Joined: Tuesday 14 January 2014 0:03
- Target OS: Linux
- Domoticz version:
- Contact:
Re: Opinions on Arduino based cable connection
Thankyou for the quick response.
I shall give it a go now I have arrived home.
Im running an Uno with an Ethernet Shield 2 on it
I'll let you know how I get on
Cheers
I shall give it a go now I have arrived home.
Im running an Uno with an Ethernet Shield 2 on it
I'll let you know how I get on
Cheers
-
- Posts: 132
- Joined: Tuesday 14 January 2014 0:03
- Target OS: Linux
- Domoticz version:
- Contact:
Re: Opinions on Arduino based cable connection
Attached is the modified Code for my system with IP address and port
When I run serial monitor and I close my switch nothing happens, when I open my switch then I get the switchcmd=on
but I get no off, the the switch wont follow the status.
However in Domoticz my dummy switch does not change state, I can ping the arduino no problem, so now I am stuck.
Hope you can help cheers
Code: Select all
#define CLOSED 0 // LOW
#define UNKNOWN 2 // --- reset / force update
//INPUT PIN Numbers on Arduino
#define PIN_MUTFAK_SU 1
// Last Status of the Sensors
int MUTFAK_SUStatus = UNKNOWN;
// IDX numbers of PIR and Reed Contacts on Domoticz-Devices Page
int IDX_MUTFAK_SU = 517;
// Arduino MAC ve IP addresses
byte mac[] = {
0xDE, 0xAD, 0xBE, 0x30, 0x39, 0x01};//Random address
IPAddress ip(192,168,2,87); //IP Address of Arduino
IPAddress domoticz(192,168,2,137); // Domoticz IP Address
int port = 8081; // Domoticz Port No
EthernetClient client;
//httprequest functions, sends status info to Domoticz
// /json.htm?type=command¶m=switchlight&idx=XX&switchcmd=On
void httpRequestswitch(int IDX, String status) {
// When the connection is successful:
if (client.connect(domoticz, port)) {
#if DEBUG
Serial.print("GET /json.htm?type=command¶m=switchlight&idx=");
Serial.print(IDX);
Serial.print("&switchcmd=");
Serial.println(status);
#endif
client.print( "GET /json.htm?type=command¶m=switchlight&idx=");
client.print(IDX);
client.print("&switchcmd=");
client.print(status);
client.println( " HTTP/1.1");
client.print( "Host: ");
client.println(ip);
client.println( "Connection: close");
client.println();
client.println();
client.stop();
delay(150);
}
else {
client.stop();
}
}
int contactState(int pin)
{
// LOW -> CLOSED
// HIGH -> OPEN
return (digitalRead(pin) == HIGH)?OPEN:CLOSED;
}
void updateContactStatus()
{
int currentStatus;
const char* msg = NULL;
currentStatus = contactState(PIN_MUTFAK_SU);
if (MUTFAK_SUStatus != currentStatus)
{
MUTFAK_SUStatus = currentStatus;
if(MUTFAK_SUStatus == CLOSED) msg = "Off";
else msg = "On";
httpRequestswitch(IDX_MUTFAK_SU, msg);
return; // only one message per loop
}
}
void setup() {
pinMode(PIN_MUTFAK_SU , INPUT);
#if DEBUG
Serial.begin(9600);
Serial.println("Arduino Alarm - Domoticz Connection");
#endif
Ethernet.begin(mac, ip);
#if DEBUG
Serial.print("Arduino IP addresss: ");
delay(1000);
Serial.println(ip);
#endif
}
void loop()
{
updateContactStatus();
}
but I get no off, the the switch wont follow the status.
However in Domoticz my dummy switch does not change state, I can ping the arduino no problem, so now I am stuck.
Hope you can help cheers
- Attachments
-
- Serial Monitor.jpg (127.62 KiB) Viewed 4376 times
-
- Domoticz.jpg (304.69 KiB) Viewed 4376 times
-
- Posts: 132
- Joined: Tuesday 14 January 2014 0:03
- Target OS: Linux
- Domoticz version:
- Contact:
Re: Opinions on Arduino based cable connection
this is how my contact is wired too
- Attachments
-
- contact.jpg (88.58 KiB) Viewed 4375 times
-
- Posts: 331
- Joined: Monday 03 July 2017 19:58
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: Opinions on Arduino based cable connection
As i see; in your .ino file you are missing the #define OPEN 1:
Code: Select all
#define CLOSED 0 // LOW
#define UNKNOWN 2 // --- reset / force update
#define OPEN 1 // ADD THIS LINE
Code: Select all
http://192.168.2.137:8081/json.htm?type=command¶m=switchlight&idx=517&switchcmd=On
Code: Select all
http://192.168.2.137:8081/json.htm?type=command¶m=switchlight&idx=517&switchcmd=Off
-
- Posts: 132
- Joined: Tuesday 14 January 2014 0:03
- Target OS: Linux
- Domoticz version:
- Contact:
Re: Opinions on Arduino based cable connection
[code// SPI and Ethernet is needed for Ethernet shield
#include <SPI.h>
#include <Ethernet.h>
//DEBUG 1 Sends output to SerialPort
#define DEBUG 1
#define OPEN 1 // HIGH
#define CLOSED 0 // LOW
#define UNKNOWN 2 // --- reset / force update
//INPUT PIN Numbers on Arduino
#define PIN_MUTFAK_SU 1
// Last Status of the Sensors
int MUTFAK_SUStatus = UNKNOWN;
// IDX numbers of PIR and Reed Contacts on Domoticz-Devices Page
int IDX_MUTFAK_SU = 517;
// Arduino MAC ve IP addresses
byte mac[] = {
0xDE, 0xAD, 0xBE, 0x30, 0x39, 0x01};//Random address
IPAddress ip(192,168,2,87); //IP Address of Arduino
IPAddress domoticz(192,168,2,137); // Domoticz IP Address
int port = 8081; // Domoticz Port No
EthernetClient client;
//httprequest functions, sends status info to Domoticz
// /json.htm?type=command¶m=switchlight&idx=XX&switchcmd=On
void httpRequestswitch(int IDX, String status) {
// When the connection is successful:
if (client.connect(domoticz, port)) {
#if DEBUG
Serial.print("GET /json.htm?type=command¶m=switchlight&idx=");
Serial.print(IDX);
Serial.print("&switchcmd=");
Serial.println(status);
#endif
client.print( "GET /json.htm?type=command¶m=switchlight&idx=");
client.print(IDX);
client.print("&switchcmd=");
client.print(status);
client.println( " HTTP/1.1");
client.print( "Host: ");
client.println(ip);
client.println( "Connection: close");
client.println();
client.println();
client.stop();
delay(150);
}
else {
client.stop();
}
}
int contactState(int pin)
{
// LOW -> CLOSED
// HIGH -> OPEN
return (digitalRead(pin) == HIGH)?OPEN:CLOSED;
}
void updateContactStatus()
{
int currentStatus;
const char* msg = NULL;
currentStatus = contactState(PIN_MUTFAK_SU);
if (MUTFAK_SUStatus != currentStatus)
{
MUTFAK_SUStatus = currentStatus;
if(MUTFAK_SUStatus == CLOSED) msg = "Off";
else msg = "On";
httpRequestswitch(IDX_MUTFAK_SU, msg);
return; // only one message per loop
}
}
void setup() {
pinMode(PIN_MUTFAK_SU , INPUT);
#if DEBUG
Serial.begin(9600);
Serial.println("Arduino Alarm - Domoticz Connection");
#endif
Ethernet.begin(mac, ip);
#if DEBUG
Serial.print("Arduino IP addresss: ");
delay(1000);
Serial.println(ip);
#endif
}
void loop()
{
updateContactStatus();
}
][/code]
Right sorry my code did not upload correctly last time Define open is in there.
These lines work fine in Chrome
http://192.168.2.137:8081/json.htm?type ... tchcmd=Off
http://192.168.2.137:8081/json.htm?type ... itchcmd=On
when you start up your serial monitor does yours look the same as mine?
cheers for continued help, I am assuming for some reason the Uno and shield are not talking to Domoticz, this area is all completely new to me sorry
#include <SPI.h>
#include <Ethernet.h>
//DEBUG 1 Sends output to SerialPort
#define DEBUG 1
#define OPEN 1 // HIGH
#define CLOSED 0 // LOW
#define UNKNOWN 2 // --- reset / force update
//INPUT PIN Numbers on Arduino
#define PIN_MUTFAK_SU 1
// Last Status of the Sensors
int MUTFAK_SUStatus = UNKNOWN;
// IDX numbers of PIR and Reed Contacts on Domoticz-Devices Page
int IDX_MUTFAK_SU = 517;
// Arduino MAC ve IP addresses
byte mac[] = {
0xDE, 0xAD, 0xBE, 0x30, 0x39, 0x01};//Random address
IPAddress ip(192,168,2,87); //IP Address of Arduino
IPAddress domoticz(192,168,2,137); // Domoticz IP Address
int port = 8081; // Domoticz Port No
EthernetClient client;
//httprequest functions, sends status info to Domoticz
// /json.htm?type=command¶m=switchlight&idx=XX&switchcmd=On
void httpRequestswitch(int IDX, String status) {
// When the connection is successful:
if (client.connect(domoticz, port)) {
#if DEBUG
Serial.print("GET /json.htm?type=command¶m=switchlight&idx=");
Serial.print(IDX);
Serial.print("&switchcmd=");
Serial.println(status);
#endif
client.print( "GET /json.htm?type=command¶m=switchlight&idx=");
client.print(IDX);
client.print("&switchcmd=");
client.print(status);
client.println( " HTTP/1.1");
client.print( "Host: ");
client.println(ip);
client.println( "Connection: close");
client.println();
client.println();
client.stop();
delay(150);
}
else {
client.stop();
}
}
int contactState(int pin)
{
// LOW -> CLOSED
// HIGH -> OPEN
return (digitalRead(pin) == HIGH)?OPEN:CLOSED;
}
void updateContactStatus()
{
int currentStatus;
const char* msg = NULL;
currentStatus = contactState(PIN_MUTFAK_SU);
if (MUTFAK_SUStatus != currentStatus)
{
MUTFAK_SUStatus = currentStatus;
if(MUTFAK_SUStatus == CLOSED) msg = "Off";
else msg = "On";
httpRequestswitch(IDX_MUTFAK_SU, msg);
return; // only one message per loop
}
}
void setup() {
pinMode(PIN_MUTFAK_SU , INPUT);
#if DEBUG
Serial.begin(9600);
Serial.println("Arduino Alarm - Domoticz Connection");
#endif
Ethernet.begin(mac, ip);
#if DEBUG
Serial.print("Arduino IP addresss: ");
delay(1000);
Serial.println(ip);
#endif
}
void loop()
{
updateContactStatus();
}
][/code]
Right sorry my code did not upload correctly last time Define open is in there.
These lines work fine in Chrome
http://192.168.2.137:8081/json.htm?type ... tchcmd=Off
http://192.168.2.137:8081/json.htm?type ... itchcmd=On
when you start up your serial monitor does yours look the same as mine?
cheers for continued help, I am assuming for some reason the Uno and shield are not talking to Domoticz, this area is all completely new to me sorry
Who is online
Users browsing this forum: No registered users and 1 guest