Chat freely about anything...

User avatar
By Bill MacIntyre
#37983 I have built a temperature logger using ESC8266 01 and thanks to some help from You Tube and Instructables.com, I am successfully logging the data to ThingSpeak.
I have a few questions on what to do next.
1. I am using lua. There are 2 files, the init.lua and another file that does the data logging part.
First I am wondering if it would be a good or bad idea to use Visual Studio, since that is my dev platform of choice (currently used ESPlorer). If so I assume I would need to dump LUA and use C++ but I am not clear on that- what I would need to do to use Visual Studio (with Visual Micro I assume)
2. Whether I use VS or continue to use LUA/ESPlorer, I have my wifi user/pass hard coded.
I am not sure the best approach to allow the end user of the device to change that to use their own wifi connection. Do I need to write my own app that would allow the user to plug in to USB and select a connection and my app would re-flash the ESP?

Edited:
After thinking about #2, I was thinking that since ESPlorer shows the commands used to send a file to the device in the right side window, Maybe I merely need to replicate the same commands and send it from my custom app thru the USB port to the device. I would also need to figure out how to save the settings (like user/pass) in a file and read them back
My app would do the following:
1. Send a command to the device to get a list of WIFI connections
2. Display them for the user to select one
3. Allow the user to enter a password
4. Read the settings file from the ESC, add the new settings and flash back to the device.

I was also thinking I could instead of using a custom program do this:
Set the device mode to both. The user would connect a computer's (or phone) wireless to the device generated hotspot. The device would display a GUI to display the hotspots, allow selecting one and entering a pass and then saving the settings to the device.

Comments?
User avatar
By luboxing
#38171 It is nice to hear that you build the module! I am in the process of building something similar so I can't answer most of your questions except the last one and some comments. In the end I have some questions for you if you don't mind answering.

I've seen gadgets using the open AP mode to first setup password and then switch to regular station once things are set up. Such gadgets include Google's Chromecast, and a Wifi IP camera I have.

Regarding storing password, I'd say it is inevitable and most Wifi stations do store password for persistence. You may however encrypt it with certain libraries.

Now it is my turn for the questions. The temperature logger I am going to build is slightly more than a "dumb transceiver", or a reflector of sensor reads to the cloud. I want to build a program in ESP8266 with a buffer so that it is still able to collect data in case of network problems, and "flush" the data back to the cloud when the network is recovered.

The key question is: with LUA is it possible to run two processes/threads simultaneously so that the first one collects and save temperature data to files and the second one does the upload or hosts a HTTP server? It is probably possible to do both jobs in one LUA code but with two processes it is easier to control the workflow and timing, etc. My understanding is LUA is probably not the right tool, but resorting to C would make the coding part a lot more difficult. Any thoughts?

Regards,
Bo
User avatar
By Bill MacIntyre
#38849 I have done a quick LUA training course on PluralSight.com and although I am no expert on LUA yet, so far its looks much easier than I expected and because it is so similar to basic programming syntax (like VB.net) it is quite easy to understand most of the code I have looked at.
And in addition some things are much easier in LUA compared to VB.
For example, concatenating 2 strings using .. instead of + or & which is more like perl- takes a bit of getting used to but stuff like the fact that functions are just like any variable should really make things easier.
That said, I am assuming that we could store all of our settings like ssid and pass etc in a simple LUA table and merely write that to a file using one line of code.
Then we just read that in from the file. If you view the file it will look like LUA table syntax code but it could be read back in as if it were actual values
The following is (I think) roughly what I am thinking - quick Google search:

Code: Select allfile.remove("CRED.lua")
file.open("CRED.lua","w+")
temp = "PASS = \""..pass.."\""
file.writeline(temp)
temp = "SSID = \""..ssid.."\""
file.writeline(temp)
file.flush()
temp = nil
file.close()

Regarding :
...The temperature logger I am going to build is slightly more than a "dumb transceiver"...

Same here.
My first go is a device to log (and probably display) temps but then I need to create a device for my families small motel that uses water heating to be able to remotely monitor and control room temps. Currently rooms are often heated when empty.
I also was thinking of reading many times and writing not so many.
I don't see much need for threading because I think my device will have a lot of idle time but I had planned to read (say) every minute and write to the cloud every hour.
That cache data could be written to a temp file on the device or just kept in memory and written to the cloud once per hour.
I have looked at some stats on battery life and there is a huge difference between writing every minute compared to once per hour- something like 2 months compared to 7 years!!

Now I just need to get me some more ESP's
The one I had working disappeared and the other one I have won't work- I think I may have 5 volted it to death.

EDIT:
Maybe we will need to write cache to a temp file because to save bat life if we go into deep sleep mode to save power, it may lose the values in memory