1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

HTTP で温度と湿度を Harvest に送る

Last updated at Posted at 2021-08-08

こちらのプログラムの送信プロトコルを udp から http に変えてみました。
UDP で温度と湿度を Harvest に送る

フォルダー構造

$ tree harvest_http/
harvest_http/
├── harvest_http.ino
├── setupLTE.ino
└── temperature.ino
harvest_http.ino
// ---------------------------------------------------------------
/*
	harvest_http.ino

					Aug/08/2021
*/
// ---------------------------------------------------------------
#include <WioLTEforArduino.h>
#include <ArduinoJson.h>
#include <stdio.h>

#define URL	"http://harvest.soracom.io"
#define SENSOR_PIN	(WIOLTE_D38)
#define INTERVAL	(10000)

DynamicJsonDocument doc(1024);

WioLTE Wio;
int TemperatureAndHumidityPin;

int icount = 0;

// ---------------------------------------------------------------
void setup() {
	setupLTE();

	TemperatureAndHumidityBegin(SENSOR_PIN);

	SerialUSB.println("*** Setup completed *** Aug/08/2021 PM 18:20");
}

// ---------------------------------------------------------------
void loop() {
	char data_json[128];
	int status;
	float temp;
	float humi;
	
	SerialUSB.println("*** loop ***");

	SerialUSB.println("icount = " + String(icount));
	
	if (!TemperatureAndHumidityRead(&temp, &humi))
		{
		SerialUSB.println("ERROR! *** TemperatureAndHumidityRead");
		}
	else
		{
		SerialUSB.print("Current humidity = ");
		SerialUSB.print(humi);
		SerialUSB.print("%  ");
		SerialUSB.print("temperature = ");
		SerialUSB.print(temp);
		SerialUSB.println("C");
		}

	doc["temp"] = temp;
	doc["humi"] = humi;

	serializeJson(doc, data_json);	
	 
	SerialUSB.print("Post:");
	SerialUSB.print(data_json);
	SerialUSB.println("");

	if (!Wio.HttpPost(URL, data_json, &status))
		{
		SerialUSB.println("### ERROR! HttpPost ###");
		}
	else
		{
		SerialUSB.print("Status: ");
		SerialUSB.println(status);
 		}
 
	SerialUSB.println("### Wait.");

	Wio.LedSetRGB(0, 0, 1); 
	delay(INTERVAL / 4);
	Wio.LedSetRGB(0, 1, 0); 
	delay(INTERVAL / 4);
	Wio.LedSetRGB(1, 1, 1); 
	delay(INTERVAL / 4);
	Wio.LedSetRGB(0, 0, 0); 
	delay(INTERVAL / 4);

	icount++;
}

// ---------------------------------------------------------------

setupLTE.ino
temperature.ino
は、元と同じです。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?