I have made (collected on the internet) the following code for an arduino uno with ethernetshield.
The arduino reads an analog input every 30 seconds and then sends the value (0 - 1024) to the serial output (hyperterminal) and to Domoticz through the ethernet shield.
In Domoticz i have created a virtual sensor that should change every 30 seconds (if the analog value is changed).
The serial output is working fine but the virtual sensor in Domoticz is updated only once. When i reset the arduino the virtual sensor in Domoticz is again updated (once).
It look like there is something wrong in my loop.
This my code:
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x7D, 0x54 };
char domoticz_server[] = "172.16.1.100";
EthernetClient domoticz_client;
int sensorValue = 0;
String deel1 = "GET /json.htm?type=command¶m=udevice&idx=7&nvalue=0&svalue=";
String deel2 = "";
String deel3 = " HTTP/1.1";
String dataInput = "";
void setup(void)
{
Serial.begin(9600);
Serial.println("zet hier iets leuks..");
// start the Ethernet connection and the server:
Serial.println("Trying to get an IP address using DHCP");
if (Ethernet.begin(mac) == 0)
{
Serial.println("Failed to configure Ethernet using DHCP");
while (true)
{
;
}
}
Serial.println();
// start listening for clients
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop(void)
{
sensorValue = analogRead(A0);
deel2 = String(sensorValue);
dataInput = String(deel1 + deel2 + deel3);
Serial.println(dataInput);
Serial.println();
domoticz_client.connect(domoticz_server, 8080);
domoticz_client.println(dataInput);
//domoticz_client.println("Host: 172.16.1.101");
//domoticz_client.println("User-Agent: Mozilla/5.0");
domoticz_client.println("Connection: close");
domoticz_client.println();
delay(30000);
}
Arduino and json
Moderators: leecollings, remb0
- bitjeverkeerd
- Posts: 30
- Joined: Monday 13 April 2015 20:39
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Contact:
-
- Posts: 22
- Joined: Sunday 22 November 2015 11:10
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.5877
- Location: Finland
- Contact:
Re: Arduino and json
I have problem just like yours. Is this been soved?
-
- Posts: 140
- Joined: Wednesday 17 December 2014 17:30
- Target OS: Linux
- Domoticz version: V3.8650
- Location: Jyväskylä, Finland
- Contact:
Re: Arduino and json
Add domoticz_client.stop() before domoticz_client.connect(....
https://www.arduino.cc/en/Tutorial/WebClientRepeating
https://www.arduino.cc/en/Tutorial/WebClientRepeating
LXC(x64 Ubuntu Xenial), RFXtrx433E, MySensors
-
- Posts: 22
- Joined: Sunday 22 November 2015 11:10
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.5877
- Location: Finland
- Contact:
Re: Arduino and json
Now works as it should. I just didin't find that one.. thanks!
-
- Posts: 6
- Joined: Saturday 29 April 2017 9:16
- Target OS: NAS (Synology & others)
- Domoticz version: 2020-2
- Location: Switzerland
- Contact:
Re: Arduino and json
@Teatech,
and how did you do it now? Pls. post the solution i.e.the arduino code. Thanks
and how did you do it now? Pls. post the solution i.e.the arduino code. Thanks
Who is online
Users browsing this forum: No registered users and 1 guest