Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
55 lines (44 sloc) 1.48 KB
#include <LWiFi.h>
#include <LWiFiClient.h>
#define ARDUINO_PLATFORM
#define M2X_ENABLE_READER
#include <jsonlite.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)
char deviceId[] = "<device id>"; // Device you want to receive values
char streamName[] = "<stream name>"; // Stream you want to receive values
char m2xKey[] = "<M2X access key>"; // Your M2X access key
LWiFiClient client;
M2XStreamClient m2xClient(&client, m2xKey);
void on_data_point_found(const char* at, m2x_value value, int index, void* context, int type) {
Serial.print("Found a data point, index:");
Serial.println(index);
Serial.print("Type:");
Serial.println(type);
Serial.print("At:");
Serial.println(at);
Serial.print("Value:");
Serial.println(value.value_string);
}
void setup() {
Serial.begin(9600);
while (!Serial.available()) {}
while (Serial.available()) { Serial.read(); }
LWiFi.begin();
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
if (LWiFi.connectWPA(ssid, pass) < 0) {
Serial.println("Failed to connect to Wifi!");
/* Loop forever */
while (1) ;
}
Serial.println("Connected to wifi");
}
void loop() {
int response = m2xClient.listStreamValues(deviceId, streamName, on_data_point_found, NULL);
Serial.print("M2x client response code: ");
Serial.println(response);
if (response == -1) while(1) ;
delay(5000);
}
You can’t perform that action at this time.