Wio LTE for Arduino에서 SORACOM Harvest에 데이터 보내기

Wio LTE for Arduino에서 SORACOM Harvest에 데이터를 보내는 샘플입니다.
더미의 온도와 습도를 보내고 있습니다.

soracom_harvest_test/soracom_harvest_test.ino
#include <WioLTEforArduino.h>
#include <stdio.h>

#define INTERVAL        (6000)
#define RECEIVE_TIMEOUT (15000)

WioLTE Wio;


float tt_aa[] = {20.1, 22.3, 24.8, 25.6, 26.7, 26.1, 25.3, 24.8, 22.6, 21.7};
float hh_aa[] = {50.1, 62.3, 64.8, 75.6, 76.7, 74.1, 72.3, 64.8, 60.6, 56.7};

int icount = 0;

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! Activate ###");
    return;
  }

  SerialUSB.println("### Setup completed. *** Jul/25/2021");
}

void loop() {
  char data[100];


  float temp;
  float humi;

  int index = icount % 10;
  temp=tt_aa[index];
  humi = hh_aa[index];

  SerialUSB.println("icount = " + String(icount));

  SerialUSB.print("Current humidity = ");
  SerialUSB.print(humi);
  SerialUSB.print("%  ");
  SerialUSB.print("temperature = ");
  SerialUSB.print(temp);
  SerialUSB.println("C");
  SerialUSB.println(String(millis()/ 1000));

sprintf(data,"{\"temp\":%.1f,\"humi\":%.1f}", temp, humi);

  SerialUSB.println("### Open.");
  int connectId;
  connectId = Wio.SocketOpen("harvest.soracom.io", 8514, WIOLTE_UDP);
  if (connectId < 0) {
    SerialUSB.println("### ERROR! SocketOpen ###");
    goto err;
  }

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

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

err:
  delay(INTERVAL);
  icount++;
}

//

Soracom Harvest에서 보낸 데이터 확인


시리얼 모니터 표시

좋은 웹페이지 즐겨찾기