#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include "DHT.h"
#define DHT11_PIN 2
#define DHTTYPE DHT11
DHT dht(DHT11_PIN, DHT11);
// The commented out fragments will be useful during debugging,
// if we have the ability to display information on the serial port monitor.
// They can be removed during final production.
const char* ssid = "WIFI_SSID";
const char* password = "WIFI_PASSWORD";
// username and password for HTTP Basic Authentication
const char* authUsername = "AUTHORIZATION_USERNAME";
const char* authPassword = "AUTHORIZATION_PASSWORD";
void setup () {
WiFi.begin(ssid, password);
// Serial.begin(9600);
//
// while (WiFi.status() != WL_CONNECTED) {
//
// delay(1000);
// Serial.println("Connecting...");
//
// }
}
void loop() {
float temp = dht.readTemperature();
float hum = dht.readHumidity();
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin("http://arduino.gaway.pl/api/measurement/post/");
http.setAuthorization(authUsername,authPassword);
http.addHeader("Content-Type", "application/json");
int httpCode = http.POST("{\"temp\":" + String(temp) + ",\"humidity\":" + String(hum)+" }");
// printing HTTP response
//
// if (httpCode > 0) {
// Serial.println(httpCode);
// String payload = http.getString();
// Serial.println(payload);
// }
http.end();
}
delay(300000);
}
Replies to githubversion
Title |
Name |
Language |
UNIX |
When |
Re: githubversion |
Mustard Stork |
text |
1614975715 |
3 Years ago. |
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}