#include <SPI.h>
#include <Ethernet.h>
#include <dht11.h>
// Ethernet shield MAC address (sticker in the back)
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
/*You can find this values in your Mobile Service dashboard
server = namemobileservice.azure-mobile.net
table_name = nametable
ams_key = your keyvalue, find in home page mobile service, with a click on button MANAGE KEYS*/
const char* server = “sensorfarm.azure-mobile.net”;
const char* table_name = “tabsensor”;
const char* ams_key = “NyWPlQgRcUWHsrGwcwhHMRxVLtnItA64”;
EthernetClient client;
char buffer[64];
dht11 DHT;
#define DHT11_PIN 4
/*This method use Mobile service REST API fot to write value*/
void write_sensorvalue(double tempvalue, double humidityvalue)
{
if (client.connect(server, 80)) {
/*Table name in Mobile service*/
sprintf(buffer, “POST /tables/%s HTTP/1.1”, table_name);
client.println(buffer);
/*Sever name in Mobile Service*/
sprintf(buffer, “Host: %s”, server);
client.println(buffer);
/*Mobile Services application key*/
sprintf(buffer, “X-ZUMO-APPLICATION: %s”, ams_key);
client.println(buffer);
// JSON content type for the information
client.println(“Content-Type: application/json”);
/*Write values of temperature and humidity from DHT11 sensor*/
sprintf(buffer, “{“tempvalue”:”%f”,”humidityvalue”:”%f”}”, tempvalue, humidityvalue);
// Content length
client.print(“Content-Length: “);
client.println(strlen(buffer));
// End of headers
client.println();
// Request body
client.println(buffer);
}
else
{
Serial.println(“no connection available!”);
}
client.stop();
}
/*——————————————————-*/
/*Setup method*/
/*——————————————————-*/
void setup()
{
Serial.begin(9600);
if (Ethernet.begin(mac) == 0)
{
Serial.println(“ethernet shield failed”);
for (;;);
}
// Ethernet shield initialization:
delay(1000);
}
/*——————————————————-*/
/*Loop method*/
/*——————————————————-*/
void loop()
{
/*Read value from sensor input*/
int chk = DHT.read(DHT11_PIN);
/*Call method writ_sensorvalue and pass sensor parameter for to save on mobile service*/
write_sensorvalue((DHT.temperature), (DHT.humidity));
/*Time wait for new input data*/
delay(10000);
}
const char* server = “sensorfarm.azure-mobile.net”;
const char* table_name = “tabsensor”;
const char* ams_key = “reperibile da portale”;
char buffer[64];
dht11 DHT;
#define DHT11_PIN 4
/*Table name in Mobile service*/
sprintf(buffer, “POST /tables/%s HTTP/1.1”, table_name);
client.println(buffer);
/*Sever name in Mobile Service*/
sprintf(buffer, “Host: %s”, server);
client.println(buffer);
/*Mobile Services application key*/
sprintf(buffer, “X-ZUMO-APPLICATION: %s”, ams_key);
client.println(buffer);
// JSON content type for the information
client.println(“Content-Type: application/json”);
/*Write values of temperature and humidity from DHT11 sensor*/
sprintf(buffer, “{“tempvalue”:”%f”,”humidityvalue”:”%f”}”, tempvalue, humidityvalue);
void loop()
{
/*Read value from sensor input*/
int chk = DHT.read(DHT11_PIN);
/*Call method writ_sensorvalue and pass sensor parameter for to save on mobile service*/
write_sensorvalue((DHT.temperature), (DHT.humidity));
/*Time wait for new input data*/
delay(10000);
}