Skip to content

Instantly share code, notes, and snippets.

@mia-0032
Created December 13, 2018 08:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mia-0032/4e5228806a7b376d4d75c1685bf4bfcf to your computer and use it in GitHub Desktop.
Save mia-0032/4e5228806a7b376d4d75c1685bf4bfcf to your computer and use it in GitHub Desktop.
#include <Wio3GforArduino.h>
#include <MMA7660.h>
#define INTERVAL (1000)
#define RECEIVE_TIMEOUT (10000)
Wio3G Wio;
MMA7660 accelemeter;
void setup() {
delay(200);
SerialUSB.begin(115200);
SerialUSB.println("");
SerialUSB.println("--- START ---------------------------------------------------");
SerialUSB.println("### I/O Initialize.");
Wio.Init();
SerialUSB.println("### Power supply ON.");
Wio.PowerSupplyCellular(true);
delay(500);
SerialUSB.println("### Turn on or reset.");
if (!Wio.TurnOnOrReset()) {
SerialUSB.println("### ERROR! ###");
return;
}
SerialUSB.println("### Connecting to \"soracom.io\".");
if (!Wio.Activate("soracom.io", "sora", "sora")) {
SerialUSB.println("### ERROR! ###");
return;
}
SerialUSB.println("### Sensor Initialize.");
accelemeter.init();
SerialUSB.println("### Setup completed.");
}
void loop() {
float ax, ay, az;
char data[100];
accelemeter.getAcceleration(&ax, &ay, &az);
sprintf(data, "{\"x\":%.2f,\"y\":%.2f,\"z\":%.2f}", ax, ay, az);
SerialUSB.print("accleration of X/Y/Z: ");
SerialUSB.println(data);
SerialUSB.println("### Open.");
int connectId;
connectId = Wio.SocketOpen("harvest.soracom.io", 8514, WIO_UDP);
if (connectId < 0) {
SerialUSB.println("### ERROR! ###");
goto err;
}
SerialUSB.println("### Send.");
SerialUSB.print("Send:");
SerialUSB.print(data);
SerialUSB.println("");
if (!Wio.SocketSend(connectId, data)) {
SerialUSB.println("### ERROR! ###");
goto err_close;
}
SerialUSB.println("### Receive.");
int length;
length = Wio.SocketReceive(connectId, data, sizeof (data), RECEIVE_TIMEOUT);
if (length < 0) {
SerialUSB.println("### ERROR! ###");
goto err_close;
}
if (length == 0) {
SerialUSB.println("### RECEIVE TIMEOUT! ###");
goto err_close;
}
SerialUSB.print("Receive:");
SerialUSB.print(data);
SerialUSB.println("");
err_close:
SerialUSB.println("### Close.");
if (!Wio.SocketClose(connectId)) {
SerialUSB.println("### ERROR! ###");
goto err;
}
err:
delay(INTERVAL);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment