new to IOT

johnny78

Full Member level 5
Joined
Jun 28, 2017
Messages
270
Helped
1
Reputation
2
Reaction score
5
Trophy points
1,298
Activity points
3,462
hi Guys
it my first time to work with IOT & webservers & this stuff
i have tested the Esp01 web server & used the ip address to enter a page to control an output
what i need to design an android App to control outputs & display Values ?

any idea to start with

thanks
Johnny
 

You 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.
 
Quick and dirty way to setup MQTT (basically applies to either ESP8266 or ESP32) :




Regards, Dana.
 

h
hi Brian
i have installed Mqtt broker on my android device & installed the pubsubclient library to my arduino but im trying to use an example for test but i couldnt
the Mqtt broker asks for :
connection name
Client ID
broker web/ip address

can you help me with an example for test ?

thanks
Johnny
--- Updated ---

Quick and dirty way to setup MQTT (basically applies to either ESP8266 or ESP32) :




Regards, Dana.
thanks Dana i will test it on my esp01 asap
 

 

    johnny78

    Points: 2
    Helpful Answer Positive Rating
The connection name is anything you want, it is just so you know which you are using if there are several connections available.
Client ID is used if there are several clients on one broker. Most systems invent an ID for you if you leave it blank.
The broker IP is the IP address of the android device (or any other host) on the network. The client devices need this so they know where to connect to find the broker.
There is usually a port number needed as well, the default is 1883 but you can change it to any available port number. The port number on the broker and all connected devices must match.

Brian.
 

    johnny78

    Points: 2
    Helpful Answer Positive Rating
hi guys

i've spend yesterday evening & all today until now trying to understand what you have sent Dana but unfortunately it was more confusing
i've find an tutorial on the net which its very detailed & easy to understand
still have some questions for later

thanks all
Johnny

i've used Mymqtt android app & by entering the ip address of the client it can be connected
how to use this server with Mqtt broker
 
Last edited:

hi 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/
 
Last edited:

the best tutorial on Espnow for Esp8266 modules

https://randomnerdtutorials.com/esp-now-esp8266-nodemcu-arduino-ide

anyone interested check this\

Johnny
 

the best tutorial on Espnow for Esp8266 modules

https://randomnerdtutorials.com/esp-now-esp8266-nodemcu-arduino-ide

anyone interested check this\

Johnny
hi Guys

its ok using the 8266 is great & unfortunately i took all this time to test it
now im using 2 Esp01's to control outputs using Esp now protocol

the master is sending the data then the power is disconnected so the sequence is:
connect power send data disconnect power & i think its ok this way

the Slave is receiving data & works great but as a 24/24 non stop device what a trick should i use to reset the Esp01 automatically
i read about enhancing the Esp01 by adding external capacitor on VCC & shielding the Esp except the antenna

any suggestion?

thanks
Johnny
 

You 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.
 

thx Dana
but the Esp01 doesnt have an A/D as i know
--- Updated ---

thx Dana
but the Esp01 doesnt have an A/D as i know
im thinking of an idea to turn off the power every lets say 12 hours
i have an extra free power to do that but im thinking what source to do this operation & how can capacitor make the power loose for as long time as it can
 



 
Last edited:


Wow Dana thx i will check it
 

Why not RESET by software?

There are several ways.
By using timers and interrupts, maybe it has a watchdog,

Klaus
 

Regarding 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.
 

    johnny78

    Points: 2
    Helpful Answer Positive Rating
hi
Why not RESET by software?

There are several ways.
By using timers and interrupts, maybe it has a watchdog,

Klaus
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 ---


Bringing adc pin out.

The EZSP8266-07 brings it out -

View attachment 194393
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
--- Updated ---

im thinking of cutting off the power for a few seconds but im looking for a simple timer circuit to do this
if i use a large capacitor on the base of a transistor it will not perform reset until the capacitor is fully charged
i need the opposite operation of the timer
after turning the timer on immediately the large capacitor will keep the power cut until the capacitor is discharged

thanks
Johnny
 
Last edited:

i dont trust WDT alot & the best method
You 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.

All 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....

*****
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.
Have 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.

Klaus
 
You 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.
yes i know but when any machine fails for any reason they turn off the power for a while & re turn it on
All 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....
there is no prove the WDT will work when the MCU hangs for unexpected reason
& yes i have my experience with this earlier
Me yes
lets say i have my first Pic12c508A working since 2008 with WDT enabled coded in assembly & it works until now
maybe the WDT reset it when something wrong happen or not but i trust it
in case of what it does not do (the WDT)i want an external solution to solve this

thanks
Johnny
 

Cookies are required to use this site. You must accept them to continue using the site. Learn more…