Deium, here is the source code.
Thank you for your help.
#include<Time.h>
#include<WiFi.h>
#include<Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char ssid[] = ""; // your network SSID (name)
char pass[] = ""; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
constchar *server = "";
constchar *table_name = "sensor1";
constchar *ams_key = "";
EthernetClient client;
char buffer[100];
int led = 13;
int blinkdelay = 125;
volatilebool sendData = false;
void setup()
pinMode(led, OUTPUT);
Serial.println("In Setup()");
// attempt to connect to Wifi network:
while (status != WL_CONNECTED)
Serial.print("Attempting to connect to WPA SSID: ");
// Connect to WPA/WPA2 network:
// wait 10 seconds for connection:
// you're connected now, so print out the data:
Serial.print("You're connected to the network: ");
while (!Serial) {
; // wait for serial port to connect.
Serial.println("WiFi");
if (Ethernet.begin(mac) == 0)
Serial.println("ethernet failed");
for (;;);
// give the Ethernet shield a second to initialize:
attachInterrupt(8, MotionDetected, RISING);
Serial.println("Ready for Motion...");
void loop()
if (sendData == true)
sendData = false;
delay(1000); // Wait 1 second
void MotionDetected()
sendData = true;
void send_request()
Serial.println("\nconnecting...");
if (client.connect(server, 80)) {
Serial.print("sending ");
// POST URI
Serial.println("post");
sprintf(buffer, "POST /tables/%s HTTP/1.1", table_name);
// Host header
Serial.println("host");
sprintf(buffer, "Host: %s", server);
// Azure Mobile Services application key
Serial.println("x-zumo");
sprintf(buffer, "X-ZUMO-APPLICATION: %s", ams_key);
// JSON content type
client.println("Content-Type: application/json");
char cTime[22];
sprintf(cTime, "%04d%02d%02d:%02d%02d%02d", year(), month(), day(), hour(), minute(), second());
//sprintf(buffer, "{\"location\":\"28 Oak\", \"sublocation\":\"bed3\", \"activitytime\":\"%s\"}", cTime);
sprintf(buffer, "{\"location\":\"38 Oak\", \"sublocation\":\"bed1\", \"activitytime\":\"%s\"}", cTime);
client.print("Content-Length: ");
// End of headers
// Request body
else {
Serial.println("connection failed");
void read_response()
Serial.println("begin: read resonse");
bool print = true;
char c = ' ';
while (client.available())
// Print only until the first carriage return
if (c == '\n')
print = false;
// if (print)
Serial.print("\n");
Serial.println("end: read resonse");
void end_request()
void wait_response()
while (!client.available())
if (!client.connected())
return;
void printWifiData() {
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
// print your MAC address:
byte mac[6];
Serial.print("MAC address: ");
Serial.print(mac[5], HEX);
Serial.print(":");
Serial.print(mac[4], HEX);
Serial.print(":");
Serial.print(mac[3], HEX);
Serial.print(":");
Serial.print(mac[2], HEX);
Serial.print(":");
Serial.print(mac[1], HEX);
Serial.print(":");
Serial.println(mac[0], HEX);
void printCurrentNet() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
// print the MAC address of the router you're attached to:
byte bssid[6];
Serial.print("BSSID: ");
Serial.print(bssid[5], HEX);
Serial.print(":");
Serial.print(bssid[4], HEX);
Serial.print(":");
Serial.print(bssid[3], HEX);
Serial.print(":");
Serial.print(bssid[2], HEX);
Serial.print(":");
Serial.print(bssid[1], HEX);
Serial.print(":");
Serial.println(bssid[0], HEX);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
// print the encryption type:
byte encryption = WiFi.encryptionType();
Serial.print("Encryption Type:");
Serial.println(encryption, HEX);
void blink(intblinkDelay, intled)
digitalWrite(led, HIGH);
delay(blinkDelay);
digitalWrite(led, LOW);
delay(blinkDelay);
digitalWrite(led, HIGH);
delay(blinkDelay);
digitalWrite(led, LOW);
delay(blinkDelay);
digitalWrite(led, HIGH);
delay(blinkDelay);
digitalWrite(led, LOW);
delay(blinkDelay);