Created
June 28, 2020 16:50
-
-
Save vlazar-/8377ff33c4f4d6bee810b2737b82f2a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESP8266WiFi.h> | |
#include <WiFiClient.h> | |
#include <ESP8266HTTPClient.h> | |
String ssid = ""; | |
char pass[] = ""; | |
int port = 8080; | |
WiFiClient wifi; | |
int status = WL_IDLE_STATUS; | |
HTTPClient client; | |
void setup() { | |
Serial.begin(9600); | |
handleWifiConnection(); | |
} | |
void loop() { | |
Serial.println("pripremam POST request"); | |
String contentType = "application/x-www-form-urlencoded"; | |
String postData = "tim=121&svjetlo=212"; | |
client.begin("http://mik-iot-api.glitch.me/svjetlo"); | |
client.addHeader("Content-Type", "application/x-www-form-urlencoded"); | |
int statusCode = client.POST(postData); | |
String response = client.getString(); | |
client.end(); | |
Serial.print("Status code poslan od servera: "); | |
Serial.println(statusCode); | |
Serial.print("Response poslan od servera: "); | |
Serial.println(response); | |
delay(1000 * 60); | |
} | |
void handleWifiConnection() { | |
while ( WiFi.status() != WL_CONNECTED) { | |
Serial.print("### Wifi Connection - Attempt SSID: "); | |
Serial.println(ssid); | |
WiFi.begin(ssid, pass); | |
delay(5000); | |
} | |
Serial.print("### SSID: "); | |
Serial.println(WiFi.SSID()); | |
Serial.print("### IP Address: "); | |
IPAddress ip = WiFi.localIP(); | |
Serial.println(ip); | |
Serial.print("### signal strength (RSSI):"); | |
Serial.print(WiFi.RSSI()); | |
Serial.println(" dBm"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment