hi BrianYou can design from scratch but there are much easier solutions. For control applications I suggest using MQTT because it is a standard and available on most platforms, including Android.
Add an MQTTT (pubsub) library to your ESP program and an MQTT client on your Android device, they will talk to each other over WiFi. I use "EspMQTTClient" on ESP8266 and ESP32 devices and on my Android phone and tablet I use "IoT MQTT Panel Pro". With those I can control many devices across several WiFi links and have graphical switches, sliders, meters and other widgets to make it look nice. I also use a Raspberry Pi as the MQTT broker and it also runs "Node Red", giving me mobile access though a cheap 4G dongle and runs a webcam at the same time.
Brian.
thanks Dana i will test it on my esp01 asapQuick and dirty way to setup MQTT (basically applies to either ESP8266 or ESP32) :
Regards, Dana.
here are the examples i usehi Guys
im started to understand how it works & im interested to design my UI android app from scratch but i need more powerful Laptop
i need to use 2 Esp's to control a relay on one Esp01 with Sw on the other without http request
ive tested the examples included in the Arduino library ESP9266WiFi
set 1 Esp01 with WiFiAccessPoint example & the other with ManualWebServer example.
it works but the responce time has delay
any example of another way or protocol ?
thanks
Johnny
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
* * Neither the name of Majenko Technologies nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* Create a WiFi access point and provide a web server on it. */
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#ifndef APSSID
#define APSSID "ESPap"
#define APPSK "thereisnospoon"
#endif
/* Set these to your desired credentials. */
const char *ssid = APSSID;
const char *password = APPSK;
ESP8266WebServer server(80);
/* Just a little test message. Go to http://192.168.4.1 in a web browser
connected to this access point to see it.
*/
void handleRoot() {
server.send(200, "text/html", "<h1>You are connected</h1>");
}
void setup() {
delay(1000);
Serial.begin(115200);
Serial.println();
Serial.print("Configuring access point...");
/* You can remove the password parameter if you want the AP to be open. */
WiFi.softAP(ssid, password);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
server.on("/", handleRoot);
server.begin();
Serial.println("HTTP server started");
}
void loop() {
server.handleClient();
/*
This sketch demonstrates how to set up a simple HTTP-like server.
The server will set a GPIO pin depending on the request
http://server_ip/gpio/0 will set the GPIO2 low,
http://server_ip/gpio/1 will set the GPIO2 high
server_ip is the IP address of the ESP8266 module, will be
printed to Serial when the module is connected.
*/
#include <ESP8266WiFi.h>
#ifndef STASSID
#define STASSID "your-ssid"
#define STAPSK "your-password"
#endif
const char* ssid = STASSID;
const char* password = STAPSK;
// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);
void setup() {
Serial.begin(115200);
// prepare LED
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, 0);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print(F("Connecting to "));
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(F("."));
}
Serial.println();
Serial.println(F("WiFi connected"));
// Start the server
server.begin();
Serial.println(F("Server started"));
// Print the IP address
Serial.println(WiFi.localIP());
}
void loop() {
// Check if a client has connected
WiFiClient client = server.accept();
if (!client) { return; }
Serial.println(F("new client"));
client.setTimeout(5000); // default is 1000
// Read the first line of the request
String req = client.readStringUntil('\r');
Serial.println(F("request: "));
Serial.println(req);
// Match the request
int val;
if (req.indexOf(F("/gpio/0")) != -1) {
val = 0;
} else if (req.indexOf(F("/gpio/1")) != -1) {
val = 1;
} else {
Serial.println(F("invalid request"));
val = digitalRead(LED_BUILTIN);
}
// Set LED according to the request
digitalWrite(LED_BUILTIN, val);
// read/ignore the rest of the request
// do not client.flush(): it is for output only, see below
while (client.available()) {
// byte by byte is not very efficient
client.read();
}
// Send the response to the client
// it is OK for multiple small client.print/write,
// because nagle algorithm will group them into one single packet
client.print(F("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO is now "));
client.print((val) ? F("high") : F("low"));
client.print(F("<br><br>Click <a href='http://"));
client.print(WiFi.localIP());
client.print(F("/gpio/1'>here</a> to switch LED GPIO on, or <a href='http://"));
client.print(WiFi.localIP());
client.print(F("/gpio/0'>here</a> to switch LED GPIO off.</html>"));
// The client will actually be *flushed* then disconnected
// when the function returns and 'client' object is destroyed (out-of-scope)
// flush = ensure written data are received by the other side
Serial.println(F("Disconnecting from client"));
}
im reading about Espnow protocolhi Guys
im started to understand how it works & im interested to design my UI android app from scratch but i need more powerful Laptop
i need to use 2 Esp's to control a relay on one Esp01 with Sw on the other without http request
ive tested the examples included in the Arduino library ESP9266WiFi
set 1 Esp01 with WiFiAccessPoint example & the other with ManualWebServer example.
it works but the responce time has delay
any example of another way or protocol ?
thanks
Johnny
--- Updated ---
here are the examples i use
1:Access point
Code:Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of Majenko Technologies nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Create a WiFi access point and provide a web server on it. */ #include <ESP8266WiFi.h> #include <WiFiClient.h> #include <ESP8266WebServer.h> #ifndef APSSID #define APSSID "ESPap" #define APPSK "thereisnospoon" #endif /* Set these to your desired credentials. */ const char *ssid = APSSID; const char *password = APPSK; ESP8266WebServer server(80); /* Just a little test message. Go to http://192.168.4.1 in a web browser connected to this access point to see it. */ void handleRoot() { server.send(200, "text/html", "<h1>You are connected</h1>"); } void setup() { delay(1000); Serial.begin(115200); Serial.println(); Serial.print("Configuring access point..."); /* You can remove the password parameter if you want the AP to be open. */ WiFi.softAP(ssid, password); IPAddress myIP = WiFi.softAPIP(); Serial.print("AP IP address: "); Serial.println(myIP); server.on("/", handleRoot); server.begin(); Serial.println("HTTP server started"); } void loop() { server.handleClient();
& here is the web server sketch
Code:/* This sketch demonstrates how to set up a simple HTTP-like server. The server will set a GPIO pin depending on the request http://server_ip/gpio/0 will set the GPIO2 low, http://server_ip/gpio/1 will set the GPIO2 high server_ip is the IP address of the ESP8266 module, will be printed to Serial when the module is connected. */ #include <ESP8266WiFi.h> #ifndef STASSID #define STASSID "your-ssid" #define STAPSK "your-password" #endif const char* ssid = STASSID; const char* password = STAPSK; // Create an instance of the server // specify the port to listen on as an argument WiFiServer server(80); void setup() { Serial.begin(115200); // prepare LED pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, 0); // Connect to WiFi network Serial.println(); Serial.println(); Serial.print(F("Connecting to ")); Serial.println(ssid); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print(F(".")); } Serial.println(); Serial.println(F("WiFi connected")); // Start the server server.begin(); Serial.println(F("Server started")); // Print the IP address Serial.println(WiFi.localIP()); } void loop() { // Check if a client has connected WiFiClient client = server.accept(); if (!client) { return; } Serial.println(F("new client")); client.setTimeout(5000); // default is 1000 // Read the first line of the request String req = client.readStringUntil('\r'); Serial.println(F("request: ")); Serial.println(req); // Match the request int val; if (req.indexOf(F("/gpio/0")) != -1) { val = 0; } else if (req.indexOf(F("/gpio/1")) != -1) { val = 1; } else { Serial.println(F("invalid request")); val = digitalRead(LED_BUILTIN); } // Set LED according to the request digitalWrite(LED_BUILTIN, val); // read/ignore the rest of the request // do not client.flush(): it is for output only, see below while (client.available()) { // byte by byte is not very efficient client.read(); } // Send the response to the client // it is OK for multiple small client.print/write, // because nagle algorithm will group them into one single packet client.print(F("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO is now ")); client.print((val) ? F("high") : F("low")); client.print(F("<br><br>Click <a href='http://")); client.print(WiFi.localIP()); client.print(F("/gpio/1'>here</a> to switch LED GPIO on, or <a href='http://")); client.print(WiFi.localIP()); client.print(F("/gpio/0'>here</a> to switch LED GPIO off.</html>")); // The client will actually be *flushed* then disconnected // when the function returns and 'client' object is destroyed (out-of-scope) // flush = ensure written data are received by the other side Serial.println(F("Disconnecting from client")); }
the best tutorial on Espnow for Esp8266 moduleshi Guys
im started to understand how it works & im interested to design my UI android app from scratch but i need more powerful Laptop
i need to use 2 Esp's to control a relay on one Esp01 with Sw on the other without http request
ive tested the examples included in the Arduino library ESP9266WiFi
set 1 Esp01 with WiFiAccessPoint example & the other with ManualWebServer example.
it works but the responce time has delay
any example of another way or protocol ?
thanks
Johnny
--- Updated ---
here are the examples i use
1:Access point
Code:Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * * Neither the name of Majenko Technologies nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Create a WiFi access point and provide a web server on it. */ #include <ESP8266WiFi.h> #include <WiFiClient.h> #include <ESP8266WebServer.h> #ifndef APSSID #define APSSID "ESPap" #define APPSK "thereisnospoon" #endif /* Set these to your desired credentials. */ const char *ssid = APSSID; const char *password = APPSK; ESP8266WebServer server(80); /* Just a little test message. Go to http://192.168.4.1 in a web browser connected to this access point to see it. */ void handleRoot() { server.send(200, "text/html", "<h1>You are connected</h1>"); } void setup() { delay(1000); Serial.begin(115200); Serial.println(); Serial.print("Configuring access point..."); /* You can remove the password parameter if you want the AP to be open. */ WiFi.softAP(ssid, password); IPAddress myIP = WiFi.softAPIP(); Serial.print("AP IP address: "); Serial.println(myIP); server.on("/", handleRoot); server.begin(); Serial.println("HTTP server started"); } void loop() { server.handleClient();
& here is the web server sketch
Code:/* This sketch demonstrates how to set up a simple HTTP-like server. The server will set a GPIO pin depending on the request http://server_ip/gpio/0 will set the GPIO2 low, http://server_ip/gpio/1 will set the GPIO2 high server_ip is the IP address of the ESP8266 module, will be printed to Serial when the module is connected. */ #include <ESP8266WiFi.h> #ifndef STASSID #define STASSID "your-ssid" #define STAPSK "your-password" #endif const char* ssid = STASSID; const char* password = STAPSK; // Create an instance of the server // specify the port to listen on as an argument WiFiServer server(80); void setup() { Serial.begin(115200); // prepare LED pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, 0); // Connect to WiFi network Serial.println(); Serial.println(); Serial.print(F("Connecting to ")); Serial.println(ssid); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print(F(".")); } Serial.println(); Serial.println(F("WiFi connected")); // Start the server server.begin(); Serial.println(F("Server started")); // Print the IP address Serial.println(WiFi.localIP()); } void loop() { // Check if a client has connected WiFiClient client = server.accept(); if (!client) { return; } Serial.println(F("new client")); client.setTimeout(5000); // default is 1000 // Read the first line of the request String req = client.readStringUntil('\r'); Serial.println(F("request: ")); Serial.println(req); // Match the request int val; if (req.indexOf(F("/gpio/0")) != -1) { val = 0; } else if (req.indexOf(F("/gpio/1")) != -1) { val = 1; } else { Serial.println(F("invalid request")); val = digitalRead(LED_BUILTIN); } // Set LED according to the request digitalWrite(LED_BUILTIN, val); // read/ignore the rest of the request // do not client.flush(): it is for output only, see below while (client.available()) { // byte by byte is not very efficient client.read(); } // Send the response to the client // it is OK for multiple small client.print/write, // because nagle algorithm will group them into one single packet client.print(F("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO is now ")); client.print((val) ? F("high") : F("low")); client.print(F("<br><br>Click <a href='http://")); client.print(WiFi.localIP()); client.print(F("/gpio/1'>here</a> to switch LED GPIO on, or <a href='http://")); client.print(WiFi.localIP()); client.print(F("/gpio/0'>here</a> to switch LED GPIO off.</html>")); // The client will actually be *flushed* then disconnected // when the function returns and 'client' object is destroyed (out-of-scope) // flush = ensure written data are received by the other side Serial.println(F("Disconnecting from client")); }
--- Updated ---
im reading about Espnow protocol
https://docs.arduino.cc/tutorials/nano-esp32/esp-now/
hi Guysthe best tutorial on Espnow for Esp8266 modules
https://randomnerdtutorials.com/esp-now-esp8266-nodemcu-arduino-ide
anyone interested check this\
Johnny
thx DanaYou could monitor/measure supply V with ESP8266 A/D, and if it falls below a value do
a EEPROM write to set a flag, such that on power up it tests the flag and if set just initializes
and clear the flag. Note use a Cap to hold up power on ESP8266 long enough to finish the
EEPROM write. Use :
Q = C x V, I = C x dV/dt, so solve for C for the allowed V drop and time you need to keep the
ESP8266 running to complete the task.
Arduino IDE has example projects of EEPROM use if I am not mistaken.
Regards, Dana.
im thinking of an idea to turn off the power every lets say 12 hoursthx Dana
but the Esp01 doesnt have an A/D as i know
ESP8266 ADC - Analog Sensors
ESP8266 ADC - Analog Sensors: ESP8266 modules have the capacity to perform many useful tasks. GPIO pins can be manipulated based on digital signals to do all sorts of handy things. Expanded firmware such as NodeMCU have made these modules very flexible and have transformed them…www.instructables.com
Is it possible to have analog input on ESP-01?
PaulRB: I think the adc on esp8266 was almost an afterthought, so the circuit is pretty basic. More complex adc circuits like those on AVR chips offer a choice of references (internal 1.1V, Vcc, external etc) and a multiplexer to offer multiple adc pins. The esp has only one option (internal...forum.arduino.cc
ESP-01 read ADC and WiFi control at same time
Hello, I am using ESP-01 and i have connected an LED to its GPIO 2 (via a 220 Ohms resistor) and a potentiometer (via a voltage divider) to its ADC pin via a wire soldered separately. The LED can be successfully controlled via web page hosted on the ESP-01 written in the Arduino sketch. But the...forum.arduino.cc
KlausWhy not RESET by software?
There are several ways.
By using timers and interrupts, maybe it has a watchdog,
Klaus
hi Dana
hi
Klaus
i dont trust WDT alot & the best method when there is no solutions is to stop the power to reset
so i will use this to make sure everything is ok & no need for any person to stop the power when it hangs for any unexpected reason
& yes i quess i will use timer when the output is off to turn off the power for few seconds by using a large capacity capacitor external timer circuit
thanks
--- Updated ---
hi Dana
i dont need this risky solution to use ADC when its not necessary for my issue
the esp01 has 4 GPIO pins & im using just one of them to drive a relay so i have 3 pins free i can use it to reset the module
i can use anyone of them to reset the module & another one to turn on an extra transistor capacitor circuit to cut the power off
thanks
Johnny
im thinking of cutting off the power for a few seconds but im looking for a simple timer circuit to do thisRegarding the ADC input - yes there is one on the ESP8266 IC but it isn't brought out to the pins on the board. With care you can still use it by connecting directly to the IC pins but it isn't easy. Likewise, you can connect the timer output to the wake-up or reset pins to perform periodic resets.
Brian.
You can trust it! 100%i dont trust WDT alot & the best method
yes i know but when any machine fails for any reason they turn off the power for a while & re turn it onYou can trust it! 100%
Industry does. With high reliabilty PLCs, Airbag control, elevator control .... billion times...
I personally use internal WDTs in almost all my industrial applications. Never experienced any WDT malfunction.
there is no prove the WDT will work when the MCU hangs for unexpected reasonAll your external circuitry is way more likely to fail.
Who exactly say "it´s best method to..."?
Seems you trust a single person more than a billion times proven method....
Me yes*****
Ask yourself, ask the internet:
How often did you read by a reliable article that a watchdog inside a microcontroller did not work?
--> I can not remind a single one.
And if it happens at one particular type of microcontroller ... is there any evidence that the same is true for a different type of microcontroller?
--> I don´t think so.
And if there was a design mistake .. the manufacturer would surely solved it with the next release.
Have you ever heard of a big electrolytics capacitor failure? --> every day! Million times.
Have you read the capacitor datasheet of the expected lifetime of a capacitor? most of them: 1000h, 2000h, 8000h (still less than a year), 10.000h
Have you ever heard of lifetime limitiation of an internal WDT feature? Me not.
lets say i have my first Pic12c508A working since 2008 with WDT enabled coded in assembly & it works until nowHave you ever heard of a solder joint malfunction? --> happens every time. Whereas internel WDT needs no solder joints.
******
My recommendation: Read the microcntroller datasheet carefully abot the WDT. How to use it. How it works. What it does ... and what it does not.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?