mirror of
https://github.com/esp8266/Arduino.git
synced 2025-08-05 13:16:13 +03:00
WiFi Shield examples: added the firmware version check
This commit is contained in:
@@ -12,7 +12,8 @@
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
*/
|
||||
#include <WiFi.h>
|
||||
#include <SPI.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
char ssid[] = "yourNetwork"; // the name of your network
|
||||
int status = WL_IDLE_STATUS; // the Wifi radio's status
|
||||
@@ -28,9 +29,13 @@ void setup() {
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if ( fv != "1.1.0" )
|
||||
Serial.println("Please upgrade the firmware");
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to open SSID: ");
|
||||
@@ -64,17 +69,17 @@ void printWifiData() {
|
||||
byte mac[6];
|
||||
WiFi.macAddress(mac);
|
||||
Serial.print("MAC address: ");
|
||||
Serial.print(mac[5],HEX);
|
||||
Serial.print(mac[5], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[4],HEX);
|
||||
Serial.print(mac[4], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[3],HEX);
|
||||
Serial.print(mac[3], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[2],HEX);
|
||||
Serial.print(mac[2], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[1],HEX);
|
||||
Serial.print(mac[1], HEX);
|
||||
Serial.print(":");
|
||||
Serial.println(mac[0],HEX);
|
||||
Serial.println(mac[0], HEX);
|
||||
|
||||
// print your subnet mask:
|
||||
IPAddress subnet = WiFi.subnetMask();
|
||||
@@ -96,17 +101,17 @@ void printCurrentNet() {
|
||||
byte bssid[6];
|
||||
WiFi.BSSID(bssid);
|
||||
Serial.print("BSSID: ");
|
||||
Serial.print(bssid[5],HEX);
|
||||
Serial.print(bssid[5], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(bssid[4],HEX);
|
||||
Serial.print(bssid[4], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(bssid[3],HEX);
|
||||
Serial.print(bssid[3], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(bssid[2],HEX);
|
||||
Serial.print(bssid[2], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(bssid[1],HEX);
|
||||
Serial.print(bssid[1], HEX);
|
||||
Serial.print(":");
|
||||
Serial.println(bssid[0],HEX);
|
||||
Serial.println(bssid[0], HEX);
|
||||
|
||||
// print the received signal strength:
|
||||
long rssi = WiFi.RSSI();
|
||||
@@ -116,6 +121,6 @@ void printCurrentNet() {
|
||||
// print the encryption type:
|
||||
byte encryption = WiFi.encryptionType();
|
||||
Serial.print("Encryption Type:");
|
||||
Serial.println(encryption,HEX);
|
||||
Serial.println(encryption, HEX);
|
||||
}
|
||||
|
||||
|
@@ -22,6 +22,7 @@
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
*/
|
||||
#include <SPI.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
char ssid[] = "yourNetwork"; // your network SSID (name)
|
||||
@@ -40,9 +41,13 @@ void setup() {
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if ( fv != "1.1.0" )
|
||||
Serial.println("Please upgrade the firmware");
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to WEP network, SSID: ");
|
||||
@@ -76,17 +81,17 @@ void printWifiData() {
|
||||
byte mac[6];
|
||||
WiFi.macAddress(mac);
|
||||
Serial.print("MAC address: ");
|
||||
Serial.print(mac[5],HEX);
|
||||
Serial.print(mac[5], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[4],HEX);
|
||||
Serial.print(mac[4], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[3],HEX);
|
||||
Serial.print(mac[3], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[2],HEX);
|
||||
Serial.print(mac[2], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[1],HEX);
|
||||
Serial.print(mac[1], HEX);
|
||||
Serial.print(":");
|
||||
Serial.println(mac[0],HEX);
|
||||
Serial.println(mac[0], HEX);
|
||||
}
|
||||
|
||||
void printCurrentNet() {
|
||||
@@ -98,17 +103,17 @@ void printCurrentNet() {
|
||||
byte bssid[6];
|
||||
WiFi.BSSID(bssid);
|
||||
Serial.print("BSSID: ");
|
||||
Serial.print(bssid[5],HEX);
|
||||
Serial.print(bssid[5], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(bssid[4],HEX);
|
||||
Serial.print(bssid[4], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(bssid[3],HEX);
|
||||
Serial.print(bssid[3], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(bssid[2],HEX);
|
||||
Serial.print(bssid[2], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(bssid[1],HEX);
|
||||
Serial.print(bssid[1], HEX);
|
||||
Serial.print(":");
|
||||
Serial.println(bssid[0],HEX);
|
||||
Serial.println(bssid[0], HEX);
|
||||
|
||||
// print the received signal strength:
|
||||
long rssi = WiFi.RSSI();
|
||||
@@ -118,7 +123,7 @@ void printCurrentNet() {
|
||||
// print the encryption type:
|
||||
byte encryption = WiFi.encryptionType();
|
||||
Serial.print("Encryption Type:");
|
||||
Serial.println(encryption,HEX);
|
||||
Serial.println(encryption, HEX);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
@@ -12,7 +12,8 @@
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
*/
|
||||
#include <WiFi.h>
|
||||
#include <SPI.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
char ssid[] = "yourNetwork"; // your network SSID (name)
|
||||
char pass[] = "secretPassword"; // your network password
|
||||
@@ -29,9 +30,13 @@ void setup() {
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if ( fv != "1.1.0" )
|
||||
Serial.println("Please upgrade the firmware");
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to WPA SSID: ");
|
||||
@@ -67,17 +72,17 @@ void printWifiData() {
|
||||
byte mac[6];
|
||||
WiFi.macAddress(mac);
|
||||
Serial.print("MAC address: ");
|
||||
Serial.print(mac[5],HEX);
|
||||
Serial.print(mac[5], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[4],HEX);
|
||||
Serial.print(mac[4], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[3],HEX);
|
||||
Serial.print(mac[3], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[2],HEX);
|
||||
Serial.print(mac[2], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[1],HEX);
|
||||
Serial.print(mac[1], HEX);
|
||||
Serial.print(":");
|
||||
Serial.println(mac[0],HEX);
|
||||
Serial.println(mac[0], HEX);
|
||||
|
||||
}
|
||||
|
||||
@@ -90,17 +95,17 @@ void printCurrentNet() {
|
||||
byte bssid[6];
|
||||
WiFi.BSSID(bssid);
|
||||
Serial.print("BSSID: ");
|
||||
Serial.print(bssid[5],HEX);
|
||||
Serial.print(bssid[5], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(bssid[4],HEX);
|
||||
Serial.print(bssid[4], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(bssid[3],HEX);
|
||||
Serial.print(bssid[3], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(bssid[2],HEX);
|
||||
Serial.print(bssid[2], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(bssid[1],HEX);
|
||||
Serial.print(bssid[1], HEX);
|
||||
Serial.print(":");
|
||||
Serial.println(bssid[0],HEX);
|
||||
Serial.println(bssid[0], HEX);
|
||||
|
||||
// print the received signal strength:
|
||||
long rssi = WiFi.RSSI();
|
||||
@@ -110,7 +115,7 @@ void printCurrentNet() {
|
||||
// print the encryption type:
|
||||
byte encryption = WiFi.encryptionType();
|
||||
Serial.print("Encryption Type:");
|
||||
Serial.println(encryption,HEX);
|
||||
Serial.println(encryption, HEX);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
@@ -29,9 +29,13 @@ void setup() {
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if ( fv != "1.1.0" )
|
||||
Serial.println("Please upgrade the firmware");
|
||||
|
||||
// Print WiFi MAC address:
|
||||
printMacAddress();
|
||||
|
||||
@@ -54,17 +58,17 @@ void printMacAddress() {
|
||||
// print your MAC address:
|
||||
WiFi.macAddress(mac);
|
||||
Serial.print("MAC: ");
|
||||
Serial.print(mac[5],HEX);
|
||||
Serial.print(mac[5], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[4],HEX);
|
||||
Serial.print(mac[4], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[3],HEX);
|
||||
Serial.print(mac[3], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[2],HEX);
|
||||
Serial.print(mac[2], HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[1],HEX);
|
||||
Serial.print(mac[1], HEX);
|
||||
Serial.print(":");
|
||||
Serial.println(mac[0],HEX);
|
||||
Serial.println(mac[0], HEX);
|
||||
}
|
||||
|
||||
void listNetworks() {
|
||||
@@ -74,7 +78,7 @@ void listNetworks() {
|
||||
if (numSsid == -1)
|
||||
{
|
||||
Serial.println("Couldn't get a wifi connection");
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
|
||||
// print the list of networks seen:
|
||||
@@ -82,7 +86,7 @@ void listNetworks() {
|
||||
Serial.println(numSsid);
|
||||
|
||||
// print the network number and name for each network found:
|
||||
for (int thisNet = 0; thisNet<numSsid; thisNet++) {
|
||||
for (int thisNet = 0; thisNet < numSsid; thisNet++) {
|
||||
Serial.print(thisNet);
|
||||
Serial.print(") ");
|
||||
Serial.print(WiFi.SSID(thisNet));
|
||||
|
@@ -37,9 +37,13 @@ void setup() {
|
||||
// check for the presence of the shield:
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
while(true); // don't continue
|
||||
while (true); // don't continue
|
||||
}
|
||||
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if ( fv != "1.1.0" )
|
||||
Serial.println("Please upgrade the firmware");
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to Network named: ");
|
||||
|
@@ -44,9 +44,13 @@ void setup() {
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if ( fv != "1.1.0" )
|
||||
Serial.println("Please upgrade the firmware");
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to SSID: ");
|
||||
@@ -57,11 +61,12 @@ void setup() {
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
|
||||
// start the server:
|
||||
server.begin();
|
||||
// you're connected now, so print out the status:
|
||||
printWifiStatus();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
|
@@ -48,9 +48,12 @@ void setup()
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if ( fv != "1.1.0" )
|
||||
Serial.println("Please upgrade the firmware");
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
@@ -79,7 +82,7 @@ void loop()
|
||||
if ( Udp.parsePacket() ) {
|
||||
Serial.println("packet received");
|
||||
// We've received a packet, read the data from it
|
||||
Udp.read(packetBuffer,NTP_PACKET_SIZE); // read the packet into the buffer
|
||||
Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer
|
||||
|
||||
//the timestamp starts at byte 40 of the received packet and is four bytes,
|
||||
// or two words, long. First, esxtract the two words:
|
||||
@@ -116,7 +119,7 @@ void loop()
|
||||
// In the first 10 seconds of each minute, we'll want a leading '0'
|
||||
Serial.print('0');
|
||||
}
|
||||
Serial.println(epoch %60); // print the second
|
||||
Serial.println(epoch % 60); // print the second
|
||||
}
|
||||
// wait ten seconds before asking for the time again
|
||||
delay(10000);
|
||||
@@ -147,7 +150,7 @@ unsigned long sendNTPpacket(IPAddress& address)
|
||||
// you can send a packet requesting a timestamp:
|
||||
Udp.beginPacket(address, 123); //NTP requests are to port 123
|
||||
//Serial.println("4");
|
||||
Udp.write(packetBuffer,NTP_PACKET_SIZE);
|
||||
Udp.write(packetBuffer, NTP_PACKET_SIZE);
|
||||
//Serial.println("5");
|
||||
Udp.endPacket();
|
||||
//Serial.println("6");
|
||||
|
@@ -41,9 +41,13 @@ void setup() {
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if ( fv != "1.1.0" )
|
||||
Serial.println("Please upgrade the firmware");
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to SSID: ");
|
||||
@@ -66,7 +70,7 @@ void loop() {
|
||||
|
||||
// if there's data available, read a packet
|
||||
int packetSize = Udp.parsePacket();
|
||||
if(packetSize)
|
||||
if (packetSize)
|
||||
{
|
||||
Serial.print("Received packet of size ");
|
||||
Serial.println(packetSize);
|
||||
@@ -77,8 +81,8 @@ void loop() {
|
||||
Serial.println(Udp.remotePort());
|
||||
|
||||
// read the packet into packetBufffer
|
||||
int len = Udp.read(packetBuffer,255);
|
||||
if (len >0) packetBuffer[len]=0;
|
||||
int len = Udp.read(packetBuffer, 255);
|
||||
if (len > 0) packetBuffer[len] = 0;
|
||||
Serial.println("Contents:");
|
||||
Serial.println(packetBuffer);
|
||||
|
||||
|
@@ -50,9 +50,13 @@ void setup() {
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if ( fv != "1.1.0" )
|
||||
Serial.println("Please upgrade the firmware");
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while (status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to SSID: ");
|
||||
@@ -93,7 +97,7 @@ void loop() {
|
||||
client.stop();
|
||||
|
||||
// do nothing forevermore:
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,15 +1,17 @@
|
||||
/*
|
||||
Repeating Wifi Web client
|
||||
Repeating Wifi Web Client
|
||||
|
||||
This sketch connects to a a web server and makes a request
|
||||
using an Arduino Wifi shield.
|
||||
|
||||
Circuit:
|
||||
* Wifi shield attached to pins 10, 11, 12, 13
|
||||
* WiFi shield attached to pins SPI pins and pin 7
|
||||
|
||||
created 23 April 2012
|
||||
modifide 31 May 2012
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
modified 13 Jan 2014
|
||||
by Federico Vanzati
|
||||
|
||||
http://arduino.cc/en/Tutorial/WifiWebClientRepeating
|
||||
This code is in the public domain.
|
||||
@@ -32,8 +34,7 @@ char server[] = "www.arduino.cc";
|
||||
//IPAddress server(64,131,82,241);
|
||||
|
||||
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, in milliseconds
|
||||
const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milliseconds
|
||||
|
||||
void setup() {
|
||||
//Initialize serial and wait for port to open:
|
||||
@@ -46,9 +47,13 @@ void setup() {
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if ( fv != "1.1.0" )
|
||||
Serial.println("Please upgrade the firmware");
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to SSID: ");
|
||||
@@ -72,33 +77,27 @@ void loop() {
|
||||
Serial.write(c);
|
||||
}
|
||||
|
||||
// if there's no net connection, but there was one last time
|
||||
// through the loop, then stop the client:
|
||||
if (!client.connected() && lastConnected) {
|
||||
Serial.println();
|
||||
Serial.println("disconnecting.");
|
||||
client.stop();
|
||||
}
|
||||
|
||||
// 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 ten seconds have passed since your last connection,
|
||||
// then connect again and send data:
|
||||
if (millis() - lastConnectionTime > postingInterval) {
|
||||
httpRequest();
|
||||
}
|
||||
// store the state of the connection for next time through
|
||||
// the loop:
|
||||
lastConnected = client.connected();
|
||||
|
||||
}
|
||||
|
||||
// this method makes a HTTP connection to the server:
|
||||
void httpRequest() {
|
||||
// close any connection before send a new request.
|
||||
// This will free the socket on the WiFi shield
|
||||
client.stop();
|
||||
|
||||
// if there's a successful connection:
|
||||
if (client.connect(server, 80)) {
|
||||
Serial.println("connecting...");
|
||||
// send the HTTP PUT request:
|
||||
client.println("GET /latest.txt HTTP/1.1");
|
||||
client.println("Host: www.arduino.cc");
|
||||
client.println("User-Agent: arduino-ethernet");
|
||||
client.println("User-Agent: ArduinoWiFi/1.1");
|
||||
client.println("Connection: close");
|
||||
client.println();
|
||||
|
||||
@@ -108,8 +107,6 @@ void httpRequest() {
|
||||
else {
|
||||
// if you couldn't make a connection:
|
||||
Serial.println("connection failed");
|
||||
Serial.println("disconnecting.");
|
||||
client.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,7 +129,3 @@ void printWifiStatus() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -41,9 +41,13 @@ void setup() {
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if ( fv != "1.1.0" )
|
||||
Serial.println("Please upgrade the firmware");
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to SSID: ");
|
||||
|
@@ -58,9 +58,13 @@ void setup() {
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if ( fv != "1.1.0" )
|
||||
Serial.println("Please upgrade the firmware");
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to SSID: ");
|
||||
@@ -98,7 +102,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
|
||||
@@ -160,9 +164,9 @@ int getLength(int someValue) {
|
||||
// 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:
|
||||
|
@@ -63,9 +63,13 @@ void setup() {
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if ( fv != "1.1.0" )
|
||||
Serial.println("Please upgrade the firmware");
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to SSID: ");
|
||||
@@ -112,7 +116,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(dataString);
|
||||
}
|
||||
// store the state of the connection for next time through
|
||||
|
Reference in New Issue
Block a user