6 Replies Latest reply on Dec 16, 2019 3:00 PM by clem57

    ESP8266 as an IOT style device

    theresajayne

      I have been racking my Brain on how to implement what i am looking to use. Obviously I am using Arduino rather than any of the Node MCU Lua etc,

      What I am after:

       

      It will be controlling a machine that I have buttons for but also I want to have an APP on a phone that can control it from anywhere.

       

      I can program Android so that is not a problem and I can have PHP on the web as an api interface.

       

      The Process would be as follows, Device is not paired, It goes into server mode and announces its own SSID, The app would connect to this and would (like an alexa) allow entering of local Wifi credentialsonce it is connected then it will connect to the remote server and register itself along with the APP id so that this device can only be controlled by this current device.

      In the case of losing internet the device will try say 10 times at ever growing times and if it still does not connect it will again go into connect mode, however if the device has already registered on the php server then although any app can enter credentials it will revert to the id of the master controlling app when reconnected.

       

      The problem i have is how do i allow the app "using http/s" to instant control the device, I need an almost 0 latency response, someone has suggested make the ESP do a get from the server and when it times out reget, so as soon as the message comes in from the app it can respond, part of the mechanism is an up / down linear actuator and if it doesnt stop in time the carried items could be damaged so I need this level of control possibly from across the globe.

       

      How would be the best way to implement this connectivity and is there any hidden clever way of doing this sort of client-server-client connectivity.

        • Re: ESP8266 as an IOT style device
          shabaz

          Hi Theresa,

           

          As I understand (I may have misunderstood) after the initial configuration (using the ESP8266 as a WiFi access point with web server, and a local handset connecting as a WiFi client to it), any subsequent commands are to be sent from anywhere in the world, from a mobile app, through a server in the cloud, i.e.   handset->cloud service->ESP8266.

          In that case, there's no way to have almost zero-sec latency, because the path is outside of your control. There are network delays in each leg, as well as server delays in the cloud (for the packet to get inside the OS and into the app, as well as the time for the app to get CPU cycles or be started up (depending on the cloud service you're using) plus any circuit connection set-up delays if you're using mobile for any leg (applies to other mediums too, not just mobile). Keeping the TCP connection open as you're suggesting I think, could be an option, but it still won't be anywhere near real-time if you're controlling moving machinery. The modern way to resolve this is to have local intelligence so that the ESP8266 (or any other device) can autonomously decide to take over and make a decision to stop the actuator.

          That may require a device with higher compute performance and different or more sensors. Along with all of that comes other issues to be considered, e.g. reliability, redundancy, etc.

          1 of 1 people found this helpful
          • Re: ESP8266 as an IOT style device
            BigG

            Suggest trying PubNub, if latency is important. There's an Arduino library out there.

             

            Alternatively, look at Google's Firebase. Good for mobile app linkage. Quite a few Arduino libraries for Firebase out there too.

            • Re: ESP8266 as an IOT style device
              sjmill01

              When I need a low latency, "virtual wire" as in the case of replacing an RC transmitter, I go with the Xbee platform.

               

              But, for IoT where I just need a couple of pins per device such as for Home Automation, I go ESP8266 as you are thinking.  It definitely has latency, but under a second typically.  It feels darn near immediate when just sending a web socket command on the LAN.

               

              Here you will find code for the ESP8266 to catch Web Socket commands with the IoT platforms IFTTT, Push Bullet, and Alexa:

              Home Automation Mojo You Must Know Part 2: Notification

               

              Here you will find code for handling direct Web Socket communication back and forth across different devices:

              Episode 376: 4D Gaming with the MATRIX Creator (overview video)

              4D IoT Game Engine Blog (circuits and code blog)

               

              These blogs may seem a little daunting, but they cut through about 40+ hours of research to get working socket code for the ESP8266.  The code and circuits are good to have in Maker's IoT tool kit.

               

              See ya',

              Sean

              3 of 3 people found this helpful
              • Re: ESP8266 as an IOT style device
                clem57

                theresajayne Cannot give specifics, but I like this https://www.instructables.com/id/GETTING-STARTED-WITH-IoT-With-ESP8266-MicroControl/  which can give you the overview perceptive. Hope that helps.