Statistics: Posted by QuickFix — Thu Jun 01, 2023 2:39 am
server.on("/update", HTTP_POST, []() {
server.sendHeader("Connection", "close");
server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
ESP.restart();
}, []() {
HTTPUpload& upload = server.upload();
if (upload.status == UPLOAD_FILE_START) {
Serial.setDebugOutput(true);
WiFiUDP::stopAll();
Serial.printf("Update: %s\n", upload.filename.c_str());
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
if (!Update.begin(maxSketchSpace)) { //start with max available size
Update.printError(Serial);
}
} else if (upload.status == UPLOAD_FILE_WRITE) {
if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
Update.printError(Serial);
}
} else if (upload.status == UPLOAD_FILE_END) {
if (Update.end(true)) { //true to set the size to the current progress
Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
} else {
Update.printError(Serial);
}
Serial.setDebugOutput(false);
}
yield();
});
upload.status == UPLOAD_FILE_START
upload.status == UPLOAD_FILE_WRITE
upload.status == UPLOAD_FILE_END
Statistics: Posted by GastonMelo — Wed May 31, 2023 4:53 pm
Statistics: Posted by loddie — Tue Apr 25, 2023 12:24 pm
Statistics: Posted by AcmeUK — Sun Mar 19, 2023 9:41 am
Statistics: Posted by eleckits — Wed Mar 15, 2023 2:22 am
#include <ESP8266mDNS.h>
void setup() {
// Start the Wi-Fi connection
WiFi.begin("your_SSID", "your_password");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
}
// Start the mDNS responder
if (MDNS.begin("esp8266")) {
Serial.println("mDNS responder started");
} else {
Serial.println("Error setting up mDNS responder!");
}
}
void loop() {
// Your code here
}
Statistics: Posted by rooppoorali — Sat Jan 28, 2023 7:58 am
Statistics: Posted by frans eilering — Mon Jan 16, 2023 4:43 pm
Statistics: Posted by eleckits — Sun Dec 18, 2022 5:53 am
Statistics: Posted by RobertTBob — Wed Nov 23, 2022 4:22 am
Statistics: Posted by tmagafas84 — Mon Nov 07, 2022 5:03 pm
Statistics: Posted by tmagafas84 — Thu Oct 27, 2022 2:24 pm
Statistics: Posted by rooppoorali — Thu Sep 08, 2022 6:55 am
Statistics: Posted by Cyprien — Tue Sep 06, 2022 4:04 am
Statistics: Posted by AcmeUK — Sun Aug 21, 2022 5:18 am
Statistics: Posted by AcmeUK — Fri Aug 19, 2022 6:19 am
//#define MYTZ "EST5EDT,M3.2.0,M11.1.0"
#define MYTZ "EST5EDT"
void initNTP()
{
#ifdef ARDUINO_ARCH_ESP32
configTzTime(MYTZ, NTP_SERVER);
#else
configTime(MYTZ, NTP_SERVER);
#endif
unsigned long t0 = millis();
Serial.print ("Synching Time over NTP ");
time_t NOW;
int ntp_retry=500;
while( ((NOW = time(nullptr)) < NTP_MIN_VALID_EPOCH) && (ntp_retry>0)) {
delay(20);
Serial.print(".");
--ntp_retry;
}
Serial.println("");
if (ntp_retry == 0){
Serial.println("ntp init timed out");
}
unsigned long t1 = millis() - t0;
Serial.println("NTP time first synch took " + String(t1) + "ms");
Serial.println("It is now " + dateTimeStr(NOW, "%m-%d-%Y %H:%M:%S"));
}
Statistics: Posted by sprior — Mon May 30, 2022 3:03 pm
Statistics: Posted by JurajA — Mon May 09, 2022 12:39 am
Statistics: Posted by JurajA — Mon May 09, 2022 12:35 am
Statistics: Posted by dduehren — Sun May 08, 2022 9:23 am
/**
RealBasicHttp.ino
Created on: 24.05.2015
*/
#include <Arduino.h>
#include "Arduino_DebugUtils.h"
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <WiFiClient.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266Ping.h>
const char string_BSQ[] PROGMEM = "\"";
const char string_Host[] PROGMEM ="Host: ";
const char string_GET[] PROGMEM ="GET ";
const char string_switchCmd[] PROGMEM = "/cm?cmnd=Power";
const char string_ContentLen[] PROGMEM ="Content-Length: ";
const char string_ContentTypeTxt[] PROGMEM ="Content-Type: text/plain";
const char string_HTTP1P1[] PROGMEM =" HTTP/1.1";
const char string_urlBase[] PROGMEM = "http://";
//const char string_ipBase[] PROGMEM = "192.168.0.35"; //Raspberry Pi
const uint16_t serverPort = 80; //5000 for Rasp Pi, 80 for Ubuntu server
const char string_off[] PROGMEM = "off";
const char string_on[] PROGMEM = "On";
#define ipLen 17
#define HTTPport 80
#define MTempSize 160
char MTemp[MTempSize]; //General purpose buffer for many operations
char workBuffer[21]; //General purpose buffer when two are needed
const IPAddress test_ip(192,168,0,71);
bool RlyOnOff(bool OnOff, uint8_t relNo);
HTTPClient httpSW;
WiFiClient client;
char switchIP[ipLen];
int httpCode;
void setup() {
Serial.begin(115200);
establishContact();
Serial.println();
strcpy(switchIP, "191.168.0.28"); //ip address of the wireless switch
Serial.println("Connecting to wifi");
wifi_set_phy_mode (PHY_MODE_11G);
WiFi.mode(WIFI_STA);
WiFi.begin("TigerScout", "5415492012");
// wait for WiFi connection
if(WiFi.status() != WL_CONNECTED){
Serial.print(".");
delay(500);
}
Serial.println("Wifi Connected");
}
bool ONoff = true;
void loop() {
Serial.println("Begin loop");
if(Ping.ping(test_ip)){
Debug.print(DBG_INFO, F("ping succeeded"));
} else {
Debug.print(DBG_INFO, F("ping failed"));
}
// RlyOnOff(ONoff, 0);
ONoff = !ONoff;
delay (10000);
}
void establishContact() {
int counter = 0;
while ((Serial.available()<= 0)&&(counter<2)) {
Serial.println(F("0,0,0")); // send an initial string
delay(3000);
counter++;
}
}
bool RlyOnOff(bool OnOff, uint8_t relNo){
//relNo is for future expansion, requires multiple swtichIPs
int httpCode = 0;
httpSW.setReuse(false);
Debug.print(DBG_INFO, "RlyOnOff, Switch IP: %s", switchIP);
sprintf_P(MTemp, "%s%s:%d%s" ,string_urlBase,switchIP,HTTPport,string_switchCmd);
// sprintf_P(MTemp, "%s%s:%d%s" ,string_urlBase,srvIP,serverPort,string_switchCmd);
strcat(MTemp,"_"); //"%20" for Tasmota devices
if(OnOff){
strcat_P(MTemp, string_on);
} else {
strcat_P(MTemp,string_off);
}
Serial.println(MTemp);
httpSW.begin(client, MTemp);
httpCode = httpSW.GET();
if ((httpCode > 0)){
httpSW.writeToStream(&Serial);
Serial.println(" ");
Debug.print(DBG_INFO, F("HTTP %d"), httpCode);
httpSW.end();
return true;
} else {
Debug.print(DBG_ERROR, F("HTTP GET invalid response http code %d %s"),httpCode, httpSW.errorToString(httpCode).c_str());
// something wrong with connection
httpSW.end();
return false;
}
}
Statistics: Posted by dduehren — Fri May 06, 2022 12:33 am
Statistics: Posted by Hairyloon — Thu Apr 14, 2022 3:36 pm
Statistics: Posted by Inq720 — Thu Apr 14, 2022 2:22 pm
Statistics: Posted by Hairyloon — Thu Apr 14, 2022 2:07 pm