Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266HTTPClient.h>
- #include <ESP8266WiFiMulti.h>
- ESP8266WiFiMulti wifiMulti;
- // REPLACE with your Domain name and URL path or IP address with path
- const char* serverName = "http://*********************";
- const uint32_t connectTimeoutMs = 5000;
- String str;
- void setup() {
- Serial.begin(115200);
- Serial.begin(115200);
- // Set in station mode
- WiFi.mode(WIFI_STA);
- // Register multi WiFi networks
- wifiMulti.addAP("1111", "pass11");
- wifiMulti.addAP("2222", "pass22");
- wifiMulti.addAP("3333", "pass33");
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- }
- void loop() {
- if (Serial.available()) {
- str = Serial.readString();
- //Check WiFi connection status
- if (wifiMulti.run(connectTimeoutMs) == WL_CONNECTED) {
- Serial.print("Connected ");
- Serial.println(WiFi.localIP());
- HTTPClient http;
- // Your Domain name with URL path or IP address with path
- http.begin(serverName);
- // Specify content-type header
- http.addHeader("Content-Type", "application/x-www-form-urlencoded");
- // Prepare your HTTP POST request data
- String httpRequestData = str;
- Serial.print("httpRequestData: ");
- Serial.println(httpRequestData);
- // Send HTTP POST request
- int httpResponseCode = http.POST(httpRequestData);
- if (httpResponseCode > 0) {
- Serial.print("HTTP Response code: ");
- Serial.println(httpResponseCode);
- }
- else {
- Serial.print("Error code: ");
- Serial.println(httpResponseCode);
- }
- http.end();
- }
- else {
- Serial.println("WiFi Disconnected");
- }
- }
- }
Add Comment
Please, Sign In to add comment