wemosでenebular
概要
wemosでenebularを叩いてみた。
postで受信ポイントにhttpリクエストを送った。
サンプルコード
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
const char * ssid = "takahatalib";
const char * password = "***";
bool Https_Get_access(String host, String url, String argument) {
BearSSL::WiFiClientSecure client;
client.setTimeout(500);
client.setInsecure();
const int httpPort = 443;
const char * host2 = host.c_str();
if (!client.connect(host2, httpPort))
{
Serial.println("connection failed");
return false;
}
client.print(String("POST ") + url + " HTTP/1.1\r\n"
+ "Host: " + host + "\r\n"
+ "User-Agent: ESP8266/1.0\r\n"
+ "x-api-key:test-api-key\r\n"
+ "content-type:application/x-www-form-urlencoded\r\n"
+ "content-length:32\r\n"
+ "Connection: close\r\n"
+ "\r\n"
+ argument + "\r\n"
+ "\r\n");
unsigned long timeout = micros();
while (client.available() == 0)
{
if (micros() - timeout > 5000000)
{
Serial.println(">>> Client Timeout !");
client.stop();
return false;
}
}
while (client.available())
{
String line = client.readStringUntil('\r');
Serial.print(line);
}
return true;
}
void setup() {
Serial.begin(115200);
delay(10);
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
String host = "***.herokuapp.com";
String url = "/sensordata";
String argument = "roomname=house1&temperature=25.7";
Https_Get_access(host, url, argument);
while(1)
{
delay(5000);
}
}
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
const char * ssid = "takahatalib";
const char * password = "***";
bool Https_Get_access(String host, String url, String argument) {
BearSSL::WiFiClientSecure client;
client.setTimeout(500);
client.setInsecure();
const int httpPort = 443;
const char * host2 = host.c_str();
if (!client.connect(host2, httpPort))
{
Serial.println("connection failed");
return false;
}
client.print(String("POST ") + url + " HTTP/1.1\r\n"
+ "Host: " + host + "\r\n"
+ "User-Agent: ESP8266/1.0\r\n"
+ "x-api-key:test-api-key\r\n"
+ "content-type:application/x-www-form-urlencoded\r\n"
+ "content-length:32\r\n"
+ "Connection: close\r\n"
+ "\r\n"
+ argument + "\r\n"
+ "\r\n");
unsigned long timeout = micros();
while (client.available() == 0)
{
if (micros() - timeout > 5000000)
{
Serial.println(">>> Client Timeout !");
client.stop();
return false;
}
}
while (client.available())
{
String line = client.readStringUntil('\r');
Serial.print(line);
}
return true;
}
void setup() {
Serial.begin(115200);
delay(10);
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
String host = "***.herokuapp.com";
String url = "/sensordata";
String argument = "roomname=house1&temperature=25.7";
Https_Get_access(host, url, argument);
while(1)
{
delay(5000);
}
}
以上。
Author And Source
この問題について(wemosでenebular), 我々は、より多くの情報をここで見つけました https://qiita.com/ohisama@github/items/e43e3549defd81543701著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .