Thanks!
I have more information. There is a first arduino at garage posting data to emoncms every 5s. Door status, temperature, power, etc…
The second arduino, at home, is posting some data every 5s and is pulling the string every 0,5s from the emoncms. Do you think this could be the problem? I suposed that the information on emoncms is stable until it’s updated every 5s. For example if the first arduino post an 1, it is stable on emoncms until there is another update at 5s with a 0. The second arduino is geting 1, 1, 1, 1… every 0,5. Perhaps the problem is here as you suggested. I could try to update emoncms every 0,5s?
Why there is no data available, 1 or 0 it’s not ever there?
Here is the complete code of pulling arduino:
//LLIBRERIES
#include <Ethernet.h>
#include <DHT.h>;
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//LEDS
int ledverd = 6;
int ledvermell = 7;
//CONSTANTS DHT
#define DHTPIN 5 // pin del sensor DHT
#define DHTTYPE DHT22 // tipus de sensor DHT
DHT dht(DHTPIN, DHTTYPE); //// Inicialitzar sensor DHT 16mhz Arduino
//VARIABLES DHT
int chk;
float hum; //Enmagatzema valor humitat
float temp; //Enmagatzema valor temperatura
//LIQUID CRYSTAL
#define BACKLIGHT_PIN 13
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
// Creat a set of new characters
const uint8_t charBitmap[][8] = {
{ 0xc, 0x12, 0x12, 0xc, 0, 0, 0, 0 },
{ 0x6, 0x9, 0x9, 0x6, 0, 0, 0, 0 },
{ 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0, 0x0 },
{ 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0, 0x0 },
{ 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0x0 },
{ 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0x0 },
{ 0x0, 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0x0 },
{ 0x0, 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0x0 }
};
//ETHERNET
byte mac[] = {xxxxx};
IPAddress ip(xxxx); // fill in an available IP address on your network here, if dhcp auto config fail
IPAddress subnet(xxxx);
IPAddress DNS(xxxx);
IPAddress gw(xxxx);
EthernetClient client; // initialize the library instance:
//CONFIGURACIÓ EMONCMS
//char server[] = "emoncms.org"; // name address for emoncms.org
// O
IPAddress server(xxxxxxx); // numeric IP for emoncms.org (no DNS)
String apikey = "1dddddddd"; //api write key
String apikey_read = "0xxxxxxx"; //api read key
int node = 2; //if 0, not used
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
boolean lastConnected = false; // state of the connection last time through the main loop
const unsigned long postingInterval = 5000; // delay between updates, in milliseconds
const unsigned long requestInterval = 500; // delay between updates, in milliseconds
void setup() {
Serial.begin(9600);
Serial.println("ARRENCANT ARDUINO CONTROL MENJADOR");
//LEDS
pinMode(ledverd, OUTPUT);
pinMode(ledvermell, OUTPUT);
//CONNECTAR ETHERNET
Ethernet.begin(mac, ip, dns, gw, subnet);
//LIQUIDCRYSTAL
lcd.begin(20, 4); // arrenca la llibreria
//ARRENCAR SENSOR DHT
dht.begin();
imprimirestat(); //imprimir estat per port serie
}
// fi de void setup
void loop() {
//ETHERNET
// if there's incoming data from the net connection.
// send it out the serial port. This is for debugging
// purposes only:
if (client.available()) {
char c = client.read();
Serial.print(c);
}
// if there's no net connection, but there was one last time
// through the loop, then stop the client:
if (!client.connected() && lastConnected) {
Serial.println();
Serial.println("Disconnecting...");
client.stop();
}
//LLEGIR VARIABLES HUM I TEMP DHT
// Wait a few seconds between measurements.
//delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
hum = dht.readHumidity();
temp= dht.readTemperature();
// if you're not connected, and at least <postingInterval> milliseconds have
// passed sinceyour last connection, then connect again and
// send data:
if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
// IMPRIMIR DADES PORT SERIE
Serial.print(temp);
Serial.print("ºC ");
Serial.print(hum);
Serial.print("% ");
Serial.println();
enviardades();
}
// store the state of the connection for next time through the loop:
lastConnected = client.connected();
//REBRE DADES EMONCMS
String sss = "";
while (client.available()) {
char c = client.read();
// Serial.print(c);
sss +=c;
}
//if(!client.connected() && (millis() - lastConnectionTime > getingInterval)) {
if(millis() - lastConnectionTime > requestInterval) {
getmultiplefeeds();
String potencia, kwh, v, te, he, pg;
int sstart = 0, send = 0;
sstart = sss.indexOf('"', send+1) + 1;
send = sss.indexOf('"', sstart);
potencia = sss.substring(sstart, send);
sstart = sss.indexOf('"', send+1) + 1;
send = sss.indexOf('"', sstart);
kwh = sss.substring(sstart, send);
sstart = sss.indexOf('"', send+1) + 1;
send = sss.indexOf('"', sstart);
v = sss.substring(sstart, send);
sstart = sss.indexOf('"', send+1) + 1;
send = sss.indexOf('"', sstart);
te = sss.substring(sstart, send);
sstart = sss.indexOf('"', send+1) + 1;
send = sss.indexOf('"', sstart);
he = sss.substring(sstart, send);
Serial.println(he);
sstart = sss.indexOf('"', send+1) + 1;
send = sss.indexOf('"', sstart);
pg = sss.substring(sstart, send);
//LEDS
if(pg.toInt() == 1) {
digitalWrite(ledvermell, HIGH);
digitalWrite(ledverd, LOW);
}
else{
digitalWrite(ledverd, HIGH);
digitalWrite(ledvermell, LOW);
}
// IMPRIMIR DADES PORT SERIE
Serial.print(potencia);
Serial.print("W ");
Serial.print(kwh);
Serial.print("kWh ");
Serial.print(v);
Serial.print("V ");
Serial.print(te);
Serial.print("ºC ");
Serial.print(he);
Serial.print("% ");
Serial.print(pg);
Serial.println();
// IMPRIMIR DADES LIQUIDCRYSTAL
if(potencia < 190) {
lcd.noBacklight();
}
else{
lcd.backlight();
}
//fila 0
lcd.setCursor(0,0);
lcd.print("EXT");
lcd.setCursor(4,0);
lcd.print(te);
lcd.setCursor(8,0);
lcd.print("C");
lcd.setCursor(11,0);
lcd.print(he);
lcd.setCursor(15,0);
lcd.print("%");
//fila 1
lcd.setCursor(0,1);
lcd.print("INT");
lcd.setCursor(4,1);
lcd.print(temp);
lcd.setCursor(8,1);
lcd.print("C");
lcd.setCursor(11,1);
lcd.print(hum);
lcd.setCursor(15,1);
lcd.print("%");
//fila 3
lcd.setCursor(2,2);
lcd.print(potencia);
lcd.setCursor(9,2);
lcd.print("W");
lcd.setCursor(11,2);
lcd.print(v);
lcd.setCursor(17,2);
lcd.print("V");
//fila 4
lcd.setCursor(0,3);
lcd.print("GARATGE");
if(pg.toInt() == 0) {
lcd.setCursor(8,3);
lcd.print("TANCAT");
}
else{
lcd.setCursor(8,3);
lcd.print("OBERT");
}
}
}
//fi de void loop
//ENVIAR DADES EMONCMS
void enviardades() {
// if there's a successful connection:
if (client.connect(server, 80)) {
Serial.println("Connectant...");
// send the HTTP GET request:
client.print("GET /emoncms/input/post?apikey=");
client.print(apikey);
if (node > 0) {
client.print("&node=");
client.print(node);
}
client.print("&json={");
client.print("Temperatura_menjador:");
client.print(temp);
client.print(",Humitat_menjador:");
client.print(hum);
client.println();
// note the time that the connection was made:
lastConnectionTime = millis();
}
else {
// if you couldn't make a connection:
Serial.println("Conexió fallada");
Serial.println("Desconnectant...");
client.stop();
}
}
//IMPRIMIR ESTAT PER PORT SÈRIE
void imprimirestat() {
// print your local IP address:
Serial.print("IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println();
}
//REBRE DADES EMONCMS
void getmultiplefeeds (){
if (client.connect(server, 80)) {
//Serial.println("CL3 is called out");
client.print("GET /emoncms/feed/fetch.json?ids=33,34,35,39,40,51&apikey=");
client.print(apikey_read);
client.println(" HTTP/1.1");
client.println("Host:aa.com");
client.println("User-Agent: Arduino-ethernet");
client.println("Connection: close");
client.println();
//return readPage(); //go and read the output
}
}
void getsinglefeed (){
if (client.connect(server, 80)) {
//Serial.println("CL3 is called out");
client.print("GET /emoncms/feed/value.json?id=39&apikey=");
client.print(apikey_read);
client.println(" HTTP/1.1");
client.println("Host:aa.com");
client.println("User-Agent: Arduino-ethernet");
client.println("Connection: close");
client.println();
//return readPage(); //go and read the output
}
}