Last active
May 3, 2018 13:58
-
-
Save KazuyukiEguchi/3a8fa487b433cf733881003eec4eb29c to your computer and use it in GitHub Desktop.
SORACOM Technology Camp 2018の会場で販売していた『PUSH for Wio』を組み立ててみました ref: https://qiita.com/KazuyukiEguchi/items/79b4a3af1d06757ddb08
This file contains hidden or 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
// Wio LTE用 PUSH-WIO用のコード | |
// Programed by Kazuyuki Eguchi | |
// Serial端子に、秋月GPSGROVE - 4ピン-ジャンパメスケーブル 20cm経由で接続 | |
// D38端子に、Grove Button(P)を接続 | |
// TinyGPSPlus 1.0.2 http://arduiniana.org/libraries/tinygpsplus/ | |
#include <WioLTEforArduino.h> | |
#include <TinyGPS++.h> | |
#include <stdio.h> | |
#define APN "soracom.io" | |
#define USERNAME "sora" | |
#define PASSWORD "sora" | |
#define BUTTON_PIN (WIOLTE_D38) | |
#define WEBHOOK_EVENTNAME "" | |
#define WEBHOOK_KEY "" | |
#define WEBHOOK_URL "https://maker.ifttt.com/trigger/"WEBHOOK_EVENTNAME"/with/key/"WEBHOOK_KEY | |
WioLTE Wio; | |
TinyGPSPlus gps; | |
char datetime[50]; | |
char gpsdata[50]; | |
void setup() { | |
pinMode(BUTTON_PIN, INPUT); | |
delay(200); | |
SerialUSB.println("### I/O Initialize."); | |
Wio.Init(); | |
Wio.LedSetRGB(0x00, 0xff, 0x00); | |
SerialUSB.println("### Power supply ON."); | |
Wio.PowerSupplyGrove(true); | |
Wio.PowerSupplyLTE(true); | |
delay(500); | |
SerialUSB.println("### Turn on or reset."); | |
if (!Wio.TurnOnOrReset()) { | |
SerialUSB.println("### ERROR! ###"); | |
return; | |
} | |
SerialUSB.println("### Connecting to \""APN"\"."); | |
if (!Wio.Activate(APN, USERNAME, PASSWORD)) { | |
SerialUSB.println("### ERROR! ###"); | |
return; | |
} | |
Serial.begin(9600); | |
sprintf(gpsdata," "); | |
sprintf(datetime," "); | |
SerialUSB.println("### Setup completed."); | |
} | |
void loop() { | |
char data[100]; | |
int status; | |
int buttonState = digitalRead(BUTTON_PIN); | |
Wio.LedSetRGB(0x00, 0x00, 0xff); | |
// SerialUSB.print(buttonState); | |
if(gps.date.isValid()) | |
{ | |
sprintf(datetime,"%04d/%02d/%02d %02d:%02d:%02d UTC" | |
,gps.date.year() | |
,gps.date.month() | |
,gps.date.day() | |
,gps.time.hour() | |
,gps.time.minute() | |
,gps.time.second()); | |
// SerialUSB.println(datetime); | |
} | |
if (gps.location.isUpdated()){ | |
sprintf(gpsdata,"%f,%f",gps.location.lat(),gps.location.lng()); | |
// SerialUSB.println(gpsdata); | |
} | |
// ボタンを押されたら、IFTTT Webhookで通知する | |
if(buttonState == 1) | |
{ | |
Wio.LedSetRGB(0xff, 0x00, 0x00); | |
SerialUSB.println("### Post."); | |
sprintf(data, "{\"value1\":\"%s\",\"value2\":\"%s\"}",datetime,gpsdata); | |
SerialUSB.print("Post:"); | |
SerialUSB.print(data); | |
SerialUSB.println(""); | |
if (!Wio.HttpPost(WEBHOOK_URL, data, &status)) { | |
SerialUSB.println("### ERROR! ###"); | |
goto err; | |
} | |
SerialUSB.print("Status:"); | |
SerialUSB.println(status); | |
} | |
err: | |
while (Serial.available()) { | |
char data = Serial.read(); | |
gps.encode(data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment