パチンコ AWS支部員 SORACOMユーザー会

ガーデン八潮実践、作ったものリスト

簡易チャタリングプログラム

#include <WioLTEforArduino.h>
#include <stdio.h>

#define BUTTON_PIN (WIOLTE_D38)
#define INTERVAL (100)

#define PUSH_SHORT 2

WioLTE Wio;

void setup() {
delay(200);

SerialUSB.println("");
SerialUSB.println("--- START ---------------------------------------------------");

SerialUSB.println("### I/O Initialize.");
Wio.Init();

SerialUSB.println("### Power supply ON.");
Wio.PowerSupplyLTE(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;
}

//Wio.PowerSupplyGrove(true);
pinMode(BUTTON_PIN, INPUT);
SerialUSB.println("### Setup completed.");
}

void loop() {
char data[100];
int connectId;
unsigned long gauge = 0;
unsigned long buttonPush = 0;

SerialUSB.println("Current humidity = ");

SerialUSB.print("digitalRead(BUTTON_PIN): ");
SerialUSB.println(digitalRead(BUTTON_PIN));
while (digitalRead(BUTTON_PIN) == 1)
{
gauge++;
SerialUSB.print("gauge: ");
SerialUSB.println(gauge);

delay(INTERVAL);
}

if (gauge > PUSH_SHORT)
{
buttonPush = 1 ;
sprintf(data, "{\"Cnt\":%lu}", buttonPush);
connectId = Wio.SocketOpen("harvest.soracom.io", 8514, WIOLTE_UDP);
if (connectId < 0) {
goto err_close;
}
}

if (!Wio.SocketSend(connectId, data)) {
SerialUSB.println("### ERROR! ###");
goto err_close;
}

SerialUSB.println("### Receive.");
int length;
do {
length = Wio.SocketReceive(connectId, data, sizeof (data));
if (length < 0) {
SerialUSB.println("### ERROR! ###");
goto err_close;
}
} while (length == 0);
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);
}