Skip to main content
Bumped by Community user
Fixed syntax highlighting.
Source Link
VE7JRO
  • 2.5k
  • 19
  • 28
  • 31
/*
** This sample Arduino sketch uploads telemetry data to Azure Mobile Services
** See the full article here: http://hypernephelist.com/2014/07/11/arduino-uno-azure-mobile-services.html
**
** Thomas Conté @tomconte
*/


#include <Bridge.h>
#include <YunClient.h>
//#include <Ethernet.h> // removed as not used by Yun
#include <SPI.h>

// not sure if these libraries are required?
#include <HttpClient.h>
#include <Process.h>

// Ethernet shield MAC address (sticker in the back)
//byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// 90:A2:DA:F8:28:38
 
// Azure Mobile Service address
// You can find this in your service dashboard
const char *server = "myhost.azure-mobile.net";
 
// Azure Mobile Service table name
// The name of the table you created
const char *table_name = "my_data";
 
// Azure Mobile Service Application Key
// You can find this key in the 'Manage Keys' menu on the dashboard
const char *ams_key = "HJRxFXXXXXXXXXXXXXXXXXXXNQoMcXXXXXXx99";
 
//EthernetClient client;
YunClient client;
 
char buffer[64];
 
/*
** Send an HTTP POST request to the Azure Mobile Service data API
*/
 
void send_request(int value)
{
  Serial.println("\nconnecting...");
 
    Serial.print("sending ");
    Serial.println(value);
 
    // POST URI
    sprintf(buffer, "POST /tables/%s HTTP/1.1", table_name);
    client.println(buffer);
 
    // Host header
    sprintf(buffer, "Host: %s", server);
    client.println(buffer);
 
    // Azure Mobile Services application key
    sprintf(buffer, "X-ZUMO-APPLICATION: %s", ams_key);
    client.println(buffer);
 
    // JSON content type
    client.println("Content-Type: application/json");
 
    // POST body
    sprintf(buffer, "{\"value\": %d}", value);
 
    // Content length
    client.print("Content-Length: ");
    client.println(strlen(buffer));
 
    // End of headers
    client.println();
 
    // Request body
    client.println(buffer);
    
}
 
/*
** Wait for response
*/
 
void wait_response()
{
  while (!client.available()) {
    if (!client.connected()) {
      return;
    }
  }
}

 
/*
** Read the response and dump to serial
*/
 
void read_response()
{
  bool print = true;
  
  while (client.available()) {
    char c = client.read();
    // Print only until the first carriage return
    if (c == '\n')
      print = false;
    if (print)
      Serial.print(c);
  }
}
 
/*
** Close the connection
*/
 
void end_request()
{
  client.stop();
}
 
/*
** Arduino Setup
*/
 
void setup()
{
Serial.begin(9600);
Serial.println("Starting Bridge");
Bridge.begin();
    
}
 
/*
** Arduino Loop
*/
 
void loop()
{
  int val = analogRead(A0);
  
  send_request(val);
  wait_response();
  read_response();
  end_request();
 
  delay(1000);
}
/*
** This sample Arduino sketch uploads telemetry data to Azure Mobile Services
** See the full article here: http://hypernephelist.com/2014/07/11/arduino-uno-azure-mobile-services.html
**
** Thomas Conté @tomconte
*/


#include <Bridge.h>
#include <YunClient.h>
//#include <Ethernet.h> // removed as not used by Yun
#include <SPI.h>

// not sure if these libraries are required?
#include <HttpClient.h>
#include <Process.h>

// Ethernet shield MAC address (sticker in the back)
//byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// 90:A2:DA:F8:28:38
 
// Azure Mobile Service address
// You can find this in your service dashboard
const char *server = "myhost.azure-mobile.net";
 
// Azure Mobile Service table name
// The name of the table you created
const char *table_name = "my_data";
 
// Azure Mobile Service Application Key
// You can find this key in the 'Manage Keys' menu on the dashboard
const char *ams_key = "HJRxFXXXXXXXXXXXXXXXXXXXNQoMcXXXXXXx99";
 
//EthernetClient client;
YunClient client;
 
char buffer[64];
 
/*
** Send an HTTP POST request to the Azure Mobile Service data API
*/
 
void send_request(int value)
{
  Serial.println("\nconnecting...");
 
    Serial.print("sending ");
    Serial.println(value);
 
    // POST URI
    sprintf(buffer, "POST /tables/%s HTTP/1.1", table_name);
    client.println(buffer);
 
    // Host header
    sprintf(buffer, "Host: %s", server);
    client.println(buffer);
 
    // Azure Mobile Services application key
    sprintf(buffer, "X-ZUMO-APPLICATION: %s", ams_key);
    client.println(buffer);
 
    // JSON content type
    client.println("Content-Type: application/json");
 
    // POST body
    sprintf(buffer, "{\"value\": %d}", value);
 
    // Content length
    client.print("Content-Length: ");
    client.println(strlen(buffer));
 
    // End of headers
    client.println();
 
    // Request body
    client.println(buffer);
    
}
 
/*
** Wait for response
*/
 
void wait_response()
{
  while (!client.available()) {
    if (!client.connected()) {
      return;
    }
  }
}

 
/*
** Read the response and dump to serial
*/
 
void read_response()
{
  bool print = true;
  
  while (client.available()) {
    char c = client.read();
    // Print only until the first carriage return
    if (c == '\n')
      print = false;
    if (print)
      Serial.print(c);
  }
}
 
/*
** Close the connection
*/
 
void end_request()
{
  client.stop();
}
 
/*
** Arduino Setup
*/
 
void setup()
{
Serial.begin(9600);
Serial.println("Starting Bridge");
Bridge.begin();
    
}
 
/*
** Arduino Loop
*/
 
void loop()
{
  int val = analogRead(A0);
  
  send_request(val);
  wait_response();
  read_response();
  end_request();
 
  delay(1000);
}
/*
** This sample Arduino sketch uploads telemetry data to Azure Mobile Services
** See the full article here: http://hypernephelist.com/2014/07/11/arduino-uno-azure-mobile-services.html
**
** Thomas Conté @tomconte
*/


#include <Bridge.h>
#include <YunClient.h>
//#include <Ethernet.h> // removed as not used by Yun
#include <SPI.h>

// not sure if these libraries are required?
#include <HttpClient.h>
#include <Process.h>

// Ethernet shield MAC address (sticker in the back)
//byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// 90:A2:DA:F8:28:38
 
// Azure Mobile Service address
// You can find this in your service dashboard
const char *server = "myhost.azure-mobile.net";
 
// Azure Mobile Service table name
// The name of the table you created
const char *table_name = "my_data";
 
// Azure Mobile Service Application Key
// You can find this key in the 'Manage Keys' menu on the dashboard
const char *ams_key = "HJRxFXXXXXXXXXXXXXXXXXXXNQoMcXXXXXXx99";
 
//EthernetClient client;
YunClient client;
 
char buffer[64];
 
/*
** Send an HTTP POST request to the Azure Mobile Service data API
*/
 
void send_request(int value)
{
  Serial.println("\nconnecting...");
 
    Serial.print("sending ");
    Serial.println(value);
 
    // POST URI
    sprintf(buffer, "POST /tables/%s HTTP/1.1", table_name);
    client.println(buffer);
 
    // Host header
    sprintf(buffer, "Host: %s", server);
    client.println(buffer);
 
    // Azure Mobile Services application key
    sprintf(buffer, "X-ZUMO-APPLICATION: %s", ams_key);
    client.println(buffer);
 
    // JSON content type
    client.println("Content-Type: application/json");
 
    // POST body
    sprintf(buffer, "{\"value\": %d}", value);
 
    // Content length
    client.print("Content-Length: ");
    client.println(strlen(buffer));
 
    // End of headers
    client.println();
 
    // Request body
    client.println(buffer);
    
}
 
/*
** Wait for response
*/
 
void wait_response()
{
  while (!client.available()) {
    if (!client.connected()) {
      return;
    }
  }
}

 
/*
** Read the response and dump to serial
*/
 
void read_response()
{
  bool print = true;
  
  while (client.available()) {
    char c = client.read();
    // Print only until the first carriage return
    if (c == '\n')
      print = false;
    if (print)
      Serial.print(c);
  }
}
 
/*
** Close the connection
*/
 
void end_request()
{
  client.stop();
}
 
/*
** Arduino Setup
*/
 
void setup()
{
Serial.begin(9600);
Serial.println("Starting Bridge");
Bridge.begin();
    
}
 
/*
** Arduino Loop
*/
 
void loop()
{
  int val = analogRead(A0);
  
  send_request(val);
  wait_response();
  read_response();
  end_request();
 
  delay(1000);
}
/*
** This sample Arduino sketch uploads telemetry data to Azure Mobile Services
** See the full article here: http://hypernephelist.com/2014/07/11/arduino-uno-azure-mobile-services.html
**
** Thomas Conté @tomconte
*/


#include <Bridge.h>
#include <YunClient.h>
//#include <Ethernet.h> // removed as not used by Yun
#include <SPI.h>

// not sure if these libraries are required?
#include <HttpClient.h>
#include <Process.h>

// Ethernet shield MAC address (sticker in the back)
//byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// 90:A2:DA:F8:28:38
 
// Azure Mobile Service address
// You can find this in your service dashboard
const char *server = "myhost.azure-mobile.net";
 
// Azure Mobile Service table name
// The name of the table you created
const char *table_name = "my_data";
 
// Azure Mobile Service Application Key
// You can find this key in the 'Manage Keys' menu on the dashboard
const char *ams_key = "HJRxFXXXXXXXXXXXXXXXXXXXNQoMcXXXXXXx99";
 
//EthernetClient client;
YunClient client;
 
char buffer[64];
 
/*
** Send an HTTP POST request to the Azure Mobile Service data API
*/
 
void send_request(int value)
{
  Serial.println("\nconnecting...");
 
    Serial.print("sending ");
    Serial.println(value);
 
    // POST URI
    sprintf(buffer, "POST /tables/%s HTTP/1.1", table_name);
    client.println(buffer);
 
    // Host header
    sprintf(buffer, "Host: %s", server);
    client.println(buffer);
 
    // Azure Mobile Services application key
    sprintf(buffer, "X-ZUMO-APPLICATION: %s", ams_key);
    client.println(buffer);
 
    // JSON content type
    client.println("Content-Type: application/json");
 
    // POST body
    sprintf(buffer, "{\"value\": %d}", value);
 
    // Content length
    client.print("Content-Length: ");
    client.println(strlen(buffer));
 
    // End of headers
    client.println();
 
    // Request body
    client.println(buffer);
    
}
 
/*
** Wait for response
*/
 
void wait_response()
{
  while (!client.available()) {
    if (!client.connected()) {
      return;
    }
  }
}

 
/*
** Read the response and dump to serial
*/
 
void read_response()
{
  bool print = true;
  
  while (client.available()) {
    char c = client.read();
    // Print only until the first carriage return
    if (c == '\n')
      print = false;
    if (print)
      Serial.print(c);
  }
}
 
/*
** Close the connection
*/
 
void end_request()
{
  client.stop();
}
 
/*
** Arduino Setup
*/
 
void setup()
{
Serial.begin(9600);
Serial.println("Starting Bridge");
Bridge.begin();
    
}
 
/*
** Arduino Loop
*/
 
void loop()
{
  int val = analogRead(A0);
  
  send_request(val);
  wait_response();
  read_response();
  end_request();
 
  delay(1000);
}
Tweeted twitter.com/StackArduino/status/1020385057159163904
Code formatting and typos
Source Link
Greenonline
  • 3.2k
  • 7
  • 37
  • 49

converting arduino uno Converting Arduino Uno with Ethernet Shield sketch for Ardunino YunArduino Yún

Hi I'm new to the Arduino Yun and I'm trying to convert a sketch written for the Arduino Uno with a Ethernet Shield. The sketch does HTTP posts to Azure Mobile Services.

I've added in the Bridge.hBridge.h and YunClient.hYunClient.h libraries in place of the Ethernet.hEthernet.h one for the Uno.

converting arduino uno with Ethernet Shield sketch for Ardunino Yun

Hi I'm new to the Arduino Yun and I'm trying to convert a sketch written for the Arduino Uno with a Ethernet Shield. The sketch does HTTP posts to Azure Mobile Services.

I've added in the Bridge.h and YunClient.h libraries in place of the Ethernet.h one for the Uno.

Converting Arduino Uno with Ethernet Shield sketch for Arduino Yún

I'm new to the Arduino Yun and I'm trying to convert a sketch written for the Arduino Uno with a Ethernet Shield. The sketch does HTTP posts to Azure Mobile Services.

I've added in the Bridge.h and YunClient.h libraries in place of the Ethernet.h one for the Uno.

added 576 characters in body
Source Link
Anonymous Penguin
  • 6.4k
  • 10
  • 34
  • 62

. /* ** This sample Arduino sketch uploads telemetry data to Azure Mobile Services ** See the full article here: http://hypernephelist.com/2014/07/11/arduino-uno-azure-mobile-services.html ** ** Thomas Conté @tomconte */

#include <Bridge.h> #include <YunClient.h> //#include <Ethernet.h> // removed as not used by Yun #include <SPI.h>

// not sure if these libraries are required? #include <HttpClient.h> #include <Process.h>

// Ethernet shield MAC address (sticker in the back) //byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // 90:A2:DA:F8:28:38

// Azure Mobile Service address // You can find this in your service dashboard const char *server = "myhost.azure-mobile.net";

// Azure Mobile Service table name // The name of the table you created const char *table_name = "my_data";

// Azure Mobile Service Application Key // You can find this key in the 'Manage Keys' menu on the dashboard const char *ams_key = "HJRxFXXXXXXXXXXXXXXXXXXXNQoMcXXXXXXx99";

//EthernetClient client; YunClient client;

char buffer[64];

/* ** Send an HTTP POST request to the Azure Mobile Service data API */

void send_request(int value) { Serial.println("\nconnecting...");

/*
** This sample Arduino sketch uploads telemetry data to Azure Mobile Services
** See the full article here: http://hypernephelist.com/2014/07/11/arduino-uno-azure-mobile-services.html
**
** Thomas Conté @tomconte
*/


#include <Bridge.h>
#include <YunClient.h>
//#include <Ethernet.h> // removed as not used by Yun
#include <SPI.h>

// not sure if these libraries are required?
#include <HttpClient.h>
#include <Process.h>

// Ethernet shield MAC address (sticker in the back)
//byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// 90:A2:DA:F8:28:38
 
// Azure Mobile Service address
// You can find this in your service dashboard
const char *server = "myhost.azure-mobile.net";
 
// Azure Mobile Service table name
// The name of the table you created
const char *table_name = "my_data";
 
// Azure Mobile Service Application Key
// You can find this key in the 'Manage Keys' menu on the dashboard
const char *ams_key = "HJRxFXXXXXXXXXXXXXXXXXXXNQoMcXXXXXXx99";
 
//EthernetClient client;
YunClient client;
 
char buffer[64];
 
/*
** Send an HTTP POST request to the Azure Mobile Service data API
*/
 
void send_request(int value)
{
  Serial.println("\nconnecting...");
 
    Serial.print("sending ");
    Serial.println(value);
 
    // POST URI
    sprintf(buffer, "POST /tables/%s HTTP/1.1", table_name);
    client.println(buffer);
 
    // Host header
    sprintf(buffer, "Host: %s", server);
    client.println(buffer);
 
    // Azure Mobile Services application key
    sprintf(buffer, "X-ZUMO-APPLICATION: %s", ams_key);
    client.println(buffer);
 
    // JSON content type
    client.println("Content-Type: application/json");
 
    // POST body
    sprintf(buffer, "{\"value\": %d}", value);
 
    // Content length
    client.print("Content-Length: ");
    client.println(strlen(buffer));
 
    // End of headers
    client.println();
 
    // Request body
    client.println(buffer);
    
}
 
/*
** Wait for response
*/
 
void wait_response()
{
  while (!client.available()) {
    if (!client.connected()) {
      return;
    }
  }
}

 
/*
** Read the response and dump to serial
*/
 
void read_response()
{
  bool print = true;
  
  while (client.available()) {
    char c = client.read();
    // Print only until the first carriage return
    if (c == '\n')
      print = false;
    if (print)
      Serial.print(c);
  }
}
 
/*
** Close the connection
*/
 
void end_request()
{
  client.stop();
}
 
/*
** Arduino Setup
*/
 
void setup()
{
Serial.begin(9600);
Serial.println("Starting Bridge");
Bridge.begin();
    
}
 
/*
** Arduino Loop
*/
 
void loop()
{
  int val = analogRead(A0);
  
  send_request(val);
  wait_response();
  read_response();
  end_request();
 
  delay(1000);
}

}

/* ** Wait for response */

void wait_response() { while (!client.available()) { if (!client.connected()) { return; } } }

/* ** Read the response and dump to serial */

void read_response() { bool print = true;

while (client.available()) { char c = client.read(); // Print only until the first carriage return if (c == '\n') print = false; if (print) Serial.print(c); } }

/* ** Close the connection */

void end_request() { client.stop(); }

/* ** Arduino Setup */

void setup() { Serial.begin(9600); Serial.println("Starting Bridge"); Bridge.begin();

}

/* ** Arduino Loop */

void loop() { int val = analogRead(A0);

send_request(val); wait_response(); read_response(); end_request();

delay(1000); }

. /* ** This sample Arduino sketch uploads telemetry data to Azure Mobile Services ** See the full article here: http://hypernephelist.com/2014/07/11/arduino-uno-azure-mobile-services.html ** ** Thomas Conté @tomconte */

#include <Bridge.h> #include <YunClient.h> //#include <Ethernet.h> // removed as not used by Yun #include <SPI.h>

// not sure if these libraries are required? #include <HttpClient.h> #include <Process.h>

// Ethernet shield MAC address (sticker in the back) //byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // 90:A2:DA:F8:28:38

// Azure Mobile Service address // You can find this in your service dashboard const char *server = "myhost.azure-mobile.net";

// Azure Mobile Service table name // The name of the table you created const char *table_name = "my_data";

// Azure Mobile Service Application Key // You can find this key in the 'Manage Keys' menu on the dashboard const char *ams_key = "HJRxFXXXXXXXXXXXXXXXXXXXNQoMcXXXXXXx99";

//EthernetClient client; YunClient client;

char buffer[64];

/* ** Send an HTTP POST request to the Azure Mobile Service data API */

void send_request(int value) { Serial.println("\nconnecting...");

Serial.print("sending ");
Serial.println(value);

// POST URI
sprintf(buffer, "POST /tables/%s HTTP/1.1", table_name);
client.println(buffer);

// Host header
sprintf(buffer, "Host: %s", server);
client.println(buffer);

// Azure Mobile Services application key
sprintf(buffer, "X-ZUMO-APPLICATION: %s", ams_key);
client.println(buffer);

// JSON content type
client.println("Content-Type: application/json");

// POST body
sprintf(buffer, "{\"value\": %d}", value);

// Content length
client.print("Content-Length: ");
client.println(strlen(buffer));

// End of headers
client.println();

// Request body
client.println(buffer);

}

/* ** Wait for response */

void wait_response() { while (!client.available()) { if (!client.connected()) { return; } } }

/* ** Read the response and dump to serial */

void read_response() { bool print = true;

while (client.available()) { char c = client.read(); // Print only until the first carriage return if (c == '\n') print = false; if (print) Serial.print(c); } }

/* ** Close the connection */

void end_request() { client.stop(); }

/* ** Arduino Setup */

void setup() { Serial.begin(9600); Serial.println("Starting Bridge"); Bridge.begin();

}

/* ** Arduino Loop */

void loop() { int val = analogRead(A0);

send_request(val); wait_response(); read_response(); end_request();

delay(1000); }

/*
** This sample Arduino sketch uploads telemetry data to Azure Mobile Services
** See the full article here: http://hypernephelist.com/2014/07/11/arduino-uno-azure-mobile-services.html
**
** Thomas Conté @tomconte
*/


#include <Bridge.h>
#include <YunClient.h>
//#include <Ethernet.h> // removed as not used by Yun
#include <SPI.h>

// not sure if these libraries are required?
#include <HttpClient.h>
#include <Process.h>

// Ethernet shield MAC address (sticker in the back)
//byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// 90:A2:DA:F8:28:38
 
// Azure Mobile Service address
// You can find this in your service dashboard
const char *server = "myhost.azure-mobile.net";
 
// Azure Mobile Service table name
// The name of the table you created
const char *table_name = "my_data";
 
// Azure Mobile Service Application Key
// You can find this key in the 'Manage Keys' menu on the dashboard
const char *ams_key = "HJRxFXXXXXXXXXXXXXXXXXXXNQoMcXXXXXXx99";
 
//EthernetClient client;
YunClient client;
 
char buffer[64];
 
/*
** Send an HTTP POST request to the Azure Mobile Service data API
*/
 
void send_request(int value)
{
  Serial.println("\nconnecting...");
 
    Serial.print("sending ");
    Serial.println(value);
 
    // POST URI
    sprintf(buffer, "POST /tables/%s HTTP/1.1", table_name);
    client.println(buffer);
 
    // Host header
    sprintf(buffer, "Host: %s", server);
    client.println(buffer);
 
    // Azure Mobile Services application key
    sprintf(buffer, "X-ZUMO-APPLICATION: %s", ams_key);
    client.println(buffer);
 
    // JSON content type
    client.println("Content-Type: application/json");
 
    // POST body
    sprintf(buffer, "{\"value\": %d}", value);
 
    // Content length
    client.print("Content-Length: ");
    client.println(strlen(buffer));
 
    // End of headers
    client.println();
 
    // Request body
    client.println(buffer);
    
}
 
/*
** Wait for response
*/
 
void wait_response()
{
  while (!client.available()) {
    if (!client.connected()) {
      return;
    }
  }
}

 
/*
** Read the response and dump to serial
*/
 
void read_response()
{
  bool print = true;
  
  while (client.available()) {
    char c = client.read();
    // Print only until the first carriage return
    if (c == '\n')
      print = false;
    if (print)
      Serial.print(c);
  }
}
 
/*
** Close the connection
*/
 
void end_request()
{
  client.stop();
}
 
/*
** Arduino Setup
*/
 
void setup()
{
Serial.begin(9600);
Serial.println("Starting Bridge");
Bridge.begin();
    
}
 
/*
** Arduino Loop
*/
 
void loop()
{
  int val = analogRead(A0);
  
  send_request(val);
  wait_response();
  read_response();
  end_request();
 
  delay(1000);
}
Source Link
Loading