Arduino 言語

こちらのプログラムを goto を使わない形に書き換えてみました。
[Wio LTE for Arduino で SORACOM Harvest にデータを送る](https://qiita.com/ekzemplaro/items/ede65634b03ee8497723)
Ubuntu 21.04 にインストールした ArdunioIDE 1.8.15 で動作の確認をしました。

```text:soracom_harvest_test/soracom_harvest_test.ino
// ---------------------------------------------------------------
/*
	soracom_harvest_test.ino

					Jul/26/2021
*/
// ---------------------------------------------------------------
#include <WioLTEforArduino.h>
#include <ArduinoJson.h>
#include <stdio.h>

DynamicJsonDocument doc(1024);

#define INTERVAL        (6000)
#define RECEIVE_TIMEOUT (10000)

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, 21.0, 20.5};
float hh_aa[] = {50.2, 62.4, 64.8, 75.6, 76.7, 74.3, 72.3, 64.6, 60.5, 56.2, 53.2, 50.8};
int ll_aa[] = {10,50,100,140,220,200,180,140,110,70,40,15};
int mm_aa[] = {15,35,75,90,125,100,80,70,65,45,35,20};


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/26/2021 AM 09:16");
}

void loop() {
  char data_json[128];

  int index = icount % 12;

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

doc["temp"] = tt_aa[index];;
doc["humi"] = hh_aa[index];
doc["light"] = ll_aa[index];
doc["moist"] = mm_aa[index];

serializeJson(doc, data_json);

int connectId = udp_open_proc();

if (0 <= connectId) {

  boolean result = udp_send_proc(connectId,data_json);

  if (result)
   {
    result = udp_receive_proc(connectId);
  }

}

    udp_close_proc(connectId);
  
  delay(INTERVAL);
  icount++;
}

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

  return connectId;
}

// ---------------------------------------------------------------
void udp_close_proc(int connectId){
    SerialUSB.println("### Close.");
  if (!Wio.SocketClose(connectId)) {
    SerialUSB.println("### ERROR! SocketClose ###");
  }

}

// ---------------------------------------------------------------
boolean udp_send_proc(int connectId,char data_json[]){
    SerialUSB.println("### Send.");
  SerialUSB.print("Send:");
  SerialUSB.print(data_json);
  SerialUSB.println("");
  boolean result = Wio.SocketSend(connectId, data_json);
  if (!result){
    SerialUSB.println("### ERROR! SocketSend ###");
  }
  return result;
}

// ---------------------------------------------------------------
boolean udp_receive_proc(int connectId){
    char data_rec[128];

  boolean result = true;
  
  SerialUSB.println("### Receive.");
  int length;
  length = Wio.SocketReceive(connectId, data_rec, sizeof (data_rec), RECEIVE_TIMEOUT);
  if (length < 0) {
    SerialUSB.println("### ERROR! SocketReceive ###");
    result = false;
  }
  else if (length == 0) {
    SerialUSB.println("### RECEIVE TIMEOUT! ###");
    result = false;
  }
  else {
  SerialUSB.print("Receive:");
  SerialUSB.print(data_rec);
  SerialUSB.println("");

  return result;
  }
}
// ---------------------------------------------------------------
```