Controlling Esp unit from cloud using websockets? #732
Replies: 26 comments
-
Posted at 2017-06-26 by @gfwilliams Yes, absolutely. There's a bit of information on doing that here: http://www.espruino.com/ws If by 'Esp unit' you mean Espruino WiFi or Pico then you can use HTTPS/secure websockets, which will be a bit more secure when you're sending data over the internet. Otherwise if you're just talking about bare ESP8266 you're stuck with standard HTTP, in which case some could conceivably spy on the commands that you send. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-06-26 by Esper Thanks Gordon, I will take a look and post back instructions on how I did it or if I need help. So that the community can grow. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-06-26 by Esper Hey Gordon, |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-06-27 by Wilberforce as per the link above: http://www.espruino.com/ws WebSocket Client |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-07-13 by Esper Ok so I created a basic webpage from which you can send commands to the device over a WS connection. The node js server acts as the host and the device + browser app act as clients. When a command is sent, it is broadcasted to all devices(Will change later). The command is then checked using a switch statement and an associated function is called on the device. I will add functionality to send msgs to specific devices later on and post back to help the community. My original idea was to be able to control device over websockets from my cloud server and have total remote control over it by building a front end API. I'm not sure if websockets is the right protocol for this though, I might need to switch to MQTT or a different communication protocol. As of right now, I'm only using 1 device, but I when I scale to maybe 1000 devices this setup might get messy. What do you recommend Gordon? Server Code (NODE.JS)
WebApp Code
front-end ws setup
ESPRUINO Code
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-07-14 by @gfwilliams If you're happy with websockets and they work for you then I'd use them. MQTT is lighter weight and you can use an off the shelf server for it - however you couldn't access it directly from a webpage... If you used that you'd have to set up your MQTT server to allow MQTT over websockets as well - and then you could have your webpage use MQTT as well. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-07-14 by Esper I see I am going to further develop the very simple set up I have going. Basically, by the end, I want a nice looking UI and an underlying API which has full control over an esp unit from anywhere in the world. This would include calling functions, flashing device, and writing a custom library for some specific applications that I have in mind. Once I am done I will upload to github to share with others. Gordon I was looking at the docs for the Web IDE, and it mentions flashing/programming over websockets?! I am really interested in this idea, what is your progress? I am willing to put in time to help make that happen?! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-07-17 by Esper instead of a switch statement and parsing route, you can also just send functions as strings and have them be evaluated by the esp unit like so. (U can also use the eval function for this)
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-07-17 by Esper The only thing I am confused about is how to send the return output of a function back to my webpage?! For example if I call digitalRead(D5); The function logs either a 0 or 1 to the console. Instead I want to send the response using
I tried setting the console to a variable and then sending the variable over ws, but the msg is always empty.
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-07-17 by @gfwilliams You can also use Which type of device are you actually using? I'm working on some lower level support for the Wifi in Espruino Wifi that should make it easier to expose that kind of functionality without having to add JS code specifically for it |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-07-17 by Esper I am using a esp8266 12e developing board by NODEMCU given to me by my professor to get an initial setup going. I plan on buying ESPRUINO WIFIs so I can use https and other functionality so i can scale my device network. I wrote my own simple web ide and am using a websocket server. I'll look at the docs for Thanks, once I'm done ill put up a tutorial. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-07-17 by Esper would it be something like this? I would set the console to
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-07-18 by @gfwilliams Yes, that's right - and then when you receive websocket data you write it to LoopbackB, and job done :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-07-18 by Esper hmm it makes sense, but when I execute the code and send over something along the lines of My understanding is that I've been testing with
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-07-18 by @gfwilliams Try |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-07-18 by Esper That didn't work either, I will start debugging now, and will let you guys know when I find the solution. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-07-18 by Esper I was messing around and shifting code, I moved
I am very EXCITED will keep you guys posted. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-07-18 by Esper The issue seems to be either Im going to try and use the eval function and see if it makes a difference. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-07-18 by Esper Ok I think I know what the issue is basically the When I pass When I pass When I pass When I pass I also tried directly passing Check out the attached screenshot, it's much easier to see.
CONSOLE FROM MY WEB APP
Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-07-19 by @gfwilliams Hi - yes, I'd be pretty sure your issue is that you're calling What's happening is you call that, then the console moves out of the way to Loopback, and all code after that command gets ignored! :) Add |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-07-19 by Esper Ok so I put in the `setTimeout(function() { LoopbackA.setConsole();},100); and it WORKS!!! HUZZAH, but there is an issue, after sending over the response, it sends over an infinite stream of the error after logging the return. I have to reset manually to kill the stream. I think this is because the error msg itself counts as Webconsole below.
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-07-19 by @gfwilliams I think what you want is simply:
No function execution or anything. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-07-19 by Esper Ok Ill try that, but I think the infinite loop is being caused by the ws server broadcasting the msg to everyone. So basically if the device sends edit. I tried that and there was no response at all. Im going to work on the indvidual addressing for ws to fix the bounce back of msgs for the esp8266. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-08-23 by Esper Sorry for such a late response, my laptop broke and I had to reset up everything from scratch on a new machine. So one of my goals here was to get the REPL to be accessible over websockets. I tried the following as suggested, and it resulted in the program emitting the following error messages over websockets to my webIDE.
complete code
Error transmitted over websockets continually until program is forced to stop
The exact error msg is the following
I'm not sure what I'm doing wrong. Any insight? line 19 is just closing braces. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-08-23 by @gfwilliams You sure it's not just that the device is connecting to a server that 'echoes' the characters it receives back? Your usage of |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-08-23 by Esper Ahh, it makes sense now. My server is set to broadcast all messages to all ws devices that are connected. I'll reconfigure it with an ID system for routing. That should hopefully solve my issue. I'll keep you updated thanks! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2017-06-26 by Esper
I want to be able to send commands to my unit from anywhere in the world. I was thinking I could use websockets to do this.
I would have a server running ws and express which would server up an html page which i could use to interact with the esp unit.
The esp unit or units would serve as clients to the server? Does this sound doable?
Beta Was this translation helpful? Give feedback.
All reactions