Skip to content

Commit

Permalink
Example updates
Browse files Browse the repository at this point in the history
  • Loading branch information
conalllaverty committed Jan 4, 2018
1 parent 24fb7cb commit 7ae47b0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,39 @@

ESP8266WiFiMulti WiFiMulti;

void setup() {

USE_SERIAL.begin(115200);
// USE_SERIAL.setDebugOutput(true);
const char* ssid = "your-ssid";
const char* password = "your-password";

USE_SERIAL.println();
USE_SERIAL.println();
USE_SERIAL.println();

for(uint8_t t = 4; t > 0; t--) {
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
USE_SERIAL.flush();
delay(1000);
}
// get this from the wia dashboard. it should start with `d_sk`
const char* device_secret_key = "your-device-secret-key";

WiFiMulti.addAP("SSID", "PASSWORD");
void setup() {
USE_SERIAL.begin(115200);
//USE_SERIAL.setDebugOutput(true);

WiFi.mode(WIFI_STA);
WiFiMulti.addAP(ssid, password);
}

void loop() {
// wait for WiFi connection
if((WiFiMulti.run() == WL_CONNECTED)) {

HTTPClient http;

USE_SERIAL.print("[HTTP] begin...\n");

// configure wia rest api
http.begin("http://api.wia.io/v1/events");
http.begin("http://api.wia.io/v1/locations");

USE_SERIAL.print("[HTTP] POST...\n");

// set authorization token. replace 'd_sk_abcdef123' with your device access token
http.addHeader("Authorization", "Bearer d_sk_abcdef123");
// set authorization token
http.addHeader("Authorization", "Bearer " + String(device_secret_key));

// set content-type to json
http.addHeader("Content-Type", "application/json");

// start connection and send HTTP headers.
// start connection and send HTTP headers. replace latitude and longitude with your gps coordinates
int httpCode = http.POST("{\"name\":\"temperature\",\"data\":21.5}");

// httpCode will be negative on error
Expand All @@ -77,3 +71,4 @@ void loop() {
delay(10000);
}


32 changes: 13 additions & 19 deletions Arduino/ESP8266/PublishLocation/PublishLocation.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* PublishEvent.ino
* PublishLocation.ino
*
* Created on: 09.01.2017
*
Expand All @@ -16,40 +16,34 @@

ESP8266WiFiMulti WiFiMulti;

void setup() {

USE_SERIAL.begin(115200);
// USE_SERIAL.setDebugOutput(true);

USE_SERIAL.println();
USE_SERIAL.println();
USE_SERIAL.println();
const char* ssid = "your-ssid";
const char* password = "your-password";

for(uint8_t t = 4; t > 0; t--) {
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
USE_SERIAL.flush();
delay(1000);
}
// get this from the wia dashboard. it should start with `d_sk`
const char* device_secret_key = "your-device-secret-key";

WiFiMulti.addAP("SSID", "PASSWORD");
void setup() {
USE_SERIAL.begin(115200);
//USE_SERIAL.setDebugOutput(true);

WiFi.mode(WIFI_STA);
WiFiMulti.addAP(ssid, password);
}

void loop() {
// wait for WiFi connection
if((WiFiMulti.run() == WL_CONNECTED)) {

HTTPClient http;

USE_SERIAL.print("[HTTP] begin...\n");

// configure wia rest api
http.begin("http://api.wia.io/v1/events");
http.begin("http://api.wia.io/v1/locations");

USE_SERIAL.print("[HTTP] POST...\n");

// set authorization token. replace 'd_sk_abcdef123' with your device access token
http.addHeader("Authorization", "Bearer d_sk_abcdef123");
// set authorization token
http.addHeader("Authorization", "Bearer " + String(device_secret_key));

// set content-type to json
http.addHeader("Content-Type", "application/json");
Expand Down

0 comments on commit 7ae47b0

Please sign in to comment.