1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-10-19 21:09:48 +03:00

Run new astyle formatter against all the examples

This commit is contained in:
Federico Fissore
2013-10-21 09:58:40 +02:00
parent 3c6ee46828
commit b4c68b3dff
259 changed files with 5160 additions and 5217 deletions

View File

@@ -1,27 +1,27 @@
/*
Pachube sensor client
This sketch connects an analog sensor to Pachube (http://www.pachube.com)
using a Wiznet Ethernet shield. You can use the Arduino Ethernet shield, or
the Adafruit Ethernet shield, either one will work, as long as it's got
a Wiznet Ethernet module on board.
This example has been updated to use version 2.0 of the Pachube.com API.
This example has been updated to use version 2.0 of the Pachube.com API.
To make it work, create a feed with a datastream, and give it the ID
sensor1. Or change the code below to match your feed.
Circuit:
* Analog sensor attached to analog in 0
* Ethernet shield attached to pins 10, 11, 12, 13
created 15 March 2010
modified 9 Apr 2012
by Tom Igoe with input from Usman Haque and Joe Saavedra
http://arduino.cc/en/Tutorial/PachubeClient
This code is in the public domain.
*/
#include <SPI.h>
@@ -34,33 +34,34 @@ http://arduino.cc/en/Tutorial/PachubeClient
// assign a MAC address for the ethernet controller.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
// fill in your address here:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
// fill in an available IP address on your network here,
// for manual configuration:
IPAddress ip(10,0,1,20);
IPAddress ip(10, 0, 1, 20);
// initialize the library instance:
EthernetClient client;
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
IPAddress server(216,52,233,122); // numeric IP for api.pachube.com
IPAddress server(216, 52, 233, 122); // numeric IP for api.pachube.com
//char server[] = "api.pachube.com"; // name address for pachube API
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 = 10*1000; //delay between updates to Pachube.com
const unsigned long postingInterval = 10 * 1000; //delay between updates to Pachube.com
void setup() {
// Open serial communications and wait for port to open:
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection:
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// DHCP failed, so use a fixed IP address:
@@ -70,7 +71,7 @@ void setup() {
void loop() {
// read the analog sensor:
int sensorReading = analogRead(A0);
int sensorReading = analogRead(A0);
// if there's incoming data from the net connection.
// send it out the serial port. This is for debugging
@@ -90,7 +91,7 @@ void loop() {
// if you're not connected, and ten seconds have passed since
// your last connection, then connect again and send data:
if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
if (!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
sendData(sensorReading);
}
// store the state of the connection for next time through
@@ -127,8 +128,8 @@ void sendData(int thisData) {
// here's the actual content of the PUT request:
client.print("sensor1,");
client.println(thisData);
}
}
else {
// if you couldn't make a connection:
Serial.println("connection failed");
@@ -136,7 +137,7 @@ void sendData(int thisData) {
Serial.println("disconnecting.");
client.stop();
}
// note the time that the connection was made or attempted:
// note the time that the connection was made or attempted:
lastConnectionTime = millis();
}
@@ -149,12 +150,12 @@ void sendData(int thisData) {
int getLength(int someValue) {
// there's at least one byte:
int digits = 1;
// continually divide the value by ten,
// continually divide the value by ten,
// adding one to the digit count for each
// time you divide, until you're at 0:
int dividend = someValue /10;
int dividend = someValue / 10;
while (dividend > 0) {
dividend = dividend /10;
dividend = dividend / 10;
digits++;
}
// return the number of digits: