Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
229 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
M2XStreamClient/examples/UpdateLocationExample/UpdateLocationExample.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include <SPI.h> | ||
#include <WiFi.h> | ||
|
||
#include "M2XStreamClient.h" | ||
|
||
char ssid[] = "<ssid>"; // your network SSID (name) | ||
char pass[] = "<WPA password>"; // your network password (use for WPA, or use as key for WEP) | ||
int keyIndex = 0; // your network key Index number (needed only for WEP) | ||
|
||
int status = WL_IDLE_STATUS; | ||
char server[] = "api-m2x.att.com"; // M2X API server | ||
int port = 80; | ||
|
||
char feedId[] = "<feed id>"; // Feed you want to post to | ||
char m2xKey[] = "<M2X access key>"; // Your M2X access key | ||
|
||
char name[] = "<location name>"; // Name of current location of datasource | ||
double latitude = -37.97884; | ||
double longitude = -57.54787; // You can also read those values from a GPS | ||
double elevation = 15; | ||
|
||
WiFiClient client; | ||
M2XStreamClient m2xClient(&client, m2xKey, server, port); | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
while (!Serial) { | ||
; // wait for serial port to connect. Needed for Leonardo only | ||
} | ||
|
||
if (WiFi.status() == WL_NO_SHIELD) { | ||
Serial.println("WiFi shield not present"); | ||
while(true); | ||
} | ||
|
||
while ( status != WL_CONNECTED) { | ||
Serial.print("Attempting to connect to SSID: "); | ||
Serial.println(ssid); | ||
// Connect to WPA/WPA2 network. Change this line if using open or WEP network: | ||
status = WiFi.begin(ssid, pass); | ||
|
||
// wait 10 seconds for connection: | ||
delay(10000); | ||
} | ||
Serial.println("Connected to wifi"); | ||
printWifiStatus(); | ||
} | ||
|
||
void loop() { | ||
int response = m2xClient.updateLocation(feedId, name, latitude, longitude, | ||
elevation); | ||
Serial.print("M2x client response code: "); | ||
Serial.println(response); | ||
|
||
if (response == -1) while(1) ; | ||
|
||
delay(5000); | ||
} | ||
|
||
void printWifiStatus() { | ||
// print the SSID of the network you're attached to: | ||
Serial.print("SSID: "); | ||
Serial.println(WiFi.SSID()); | ||
|
||
// print your WiFi shield's IP address: | ||
IPAddress ip = WiFi.localIP(); | ||
Serial.print("IP Address: "); | ||
Serial.println(ip); | ||
|
||
// print the received signal strength: | ||
long rssi = WiFi.RSSI(); | ||
Serial.print("signal strength (RSSI):"); | ||
Serial.print(rssi); | ||
Serial.println(" dBm"); | ||
} |