Skip to content

Instantly share code, notes, and snippets.

@vlazar-
Created June 28, 2020 16:50
Show Gist options
  • Save vlazar-/8377ff33c4f4d6bee810b2737b82f2a5 to your computer and use it in GitHub Desktop.
Save vlazar-/8377ff33c4f4d6bee810b2737b82f2a5 to your computer and use it in GitHub Desktop.
#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