New Inquiry received by email:
Hi,
I want to use ask sensors to control the temperature at a room, using Arduino Uno, Ethernet Shield and the sensor LM35.
Running the code, I made a graph at AskSensors, but the temperature always shows 100ºC, while at Arduino monitor serial, I can see the right temperature, around 24ºC, with some variation.
This is the code I'm using:
Code: Select all
#include <SPI.h>
#include <Ethernet.h>
float temperatura
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 100); // example IPAddress ip(192, 168, 1, 100);
char server[] = "asksensors.com";
const int port = 80;
const char* apiKeyIn = "mykeyhere";
int dumData = 100;
EthernetClient client;
void setup()
{
Serial.begin(9600);
delay(1000);
while (!Serial) {
;
}
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
Ethernet.begin(mac, ip);
}
delay(1000);
Serial.println("connecting...");
if (client.connect(server, port)) {
Serial.println("connected asksensors.com");
String url = "http://asksensors.com/api.asksensors/write/";
url += apiKeyIn;
url += "?module1=";
url += dumData;
Serial.print("********** requesting URL: ");
Serial.println(url);
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + server + "\r\n" +
"Connection: close\r\n\r\n");
client.println();
Serial.println("> Request sent to ASKSENSORS");
} else {
Serial.println("connection failed");
}
}
void loop()
{
temperatura = (((float(analogRead(A0)) * 5) / 1023) - 0.5) * 100;
Serial.print("Temperatura = ");
Serial.print(temperatura);
Serial.println(" ºC ");
delay(2000);
if (client.available()) {
char c = client.read();
Serial.print(c);
}
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
while (true);
}
}
Thank you