04.10.2016
After long weekend testing, I´ve got some success with the reset/crashing problems of the ESP8266.
I found out there could be four possible reasons for this:
1- main power supply schould at least provide 500 mA of current and stable 5V. My Power supply goes up to 1A and I measured 4,75V at Vin connector from ESP8266 developement board. ESP8266 development board could reach up to 350mA for short periods in some situations (e.g. WiFi reception is very weak, etc). In normal conditions, ESP will need around 80mA. It is also important to know how much current other sensors or devices which are connected directly to ESP will consume.
In my case:
a) DHT22 temperature & humidity sensor 3,3V to 6V 1,5mA
b) BH1750 lightmeter 2,4V to 3,6V 120µA
c) PIR motion sensor 3,3V to 5V (or more?) 170µA
d) Electret microphone sensor 4,0V to 6,0V ?
e) µSD card 4,5V to 5,5V around 100mA
So 500mA main current for complete system should be enough.
2- the 3,3V PIN on ESP8266 should also provide stable 3,3V. I measured 3,32V. I read that there could be some voltage fluctuations, and to avoid this I put a 470µF electrolyt- and a small 100 nF capacitor between 3,3V PIN and GND. So if voltage gets shortly below 3,3V, this capacitors will avoid this short volage drop. Sometimes it is also recommended to use larger capacitors, e.g. 3300 µF. To keep them small, use capacitors for 6,3V. They are also cheap (around 0,30 EUR).
I´m not sure if my development board already has such a capacitor, and this solution is only for ESP8266-01 or any ESP without 3,3V voltage regulator. Maybe I will realocate this capacitor to main power input PIN (Vin).
3- I think the main reason for system crashes/resets was the reset PIN. It seems to be very sensible the the "surrounding", that´s why I connected a 10 KOhm pull-up resistance to 3,3V, and also a 100nF capacitor to GND. This worked pretty fine. Unit worked for 2 days without problems, at different locations, and with DHT22 and BH1750 and SD card connected ! Without this change, system would only work for 1 hour or less...
4- last but not least, I verified the program code and looked for some loops or functions which takes too long. I read that ESP8266 needs some time to execute internal functions to keep WiFi connected, to manage all TCP/IP stack issues, etc. For this, it is necessary to add some delay() or yield() functions to allow ESP8266 to perform this internat tasks. If not, this could also lead to system crashes. So I also inserted some short delays() / yields() in longer processing loops / functions.
Here some links to these problems and the solutions:
Reset PIN and votalge fluctuations (german)
delay(), yield(), SPI, I²C, ESP Wifi class
Next steps :
1) remove capacitors from 3,3V PIN to verify if those are not necessary
2) place electret microphone into PCB with 90° socket and connect to ESP
3) add microphone code function (integrate analog/raw noise of microphone during update-time)
4) add new SD card library
5) solder status LED with resistor, and make it work to visualize WiFi + Blynk connection running
6) extract date and time substring from google-time, and add 2 hours to GMT time (Greenwich Mean Time) for german time; probably log this into SD card with some additional sensor information
7) write code to log data into SD card, like csv-file (comma separated values). This files can be easily opened and visualized with MS Excel.
8) optimize code, check for long loops, add some debugging information (like sensor value wrong, or connection attempts, or SD card problems etc.)
29.09.2016
Here some links showing technical data of the ESP8266 12E development board:
https://smartarduino.gitbooks.io/user-manual-for-esp-12e-devkit/content/
https://github.com/acrobotic/Ai_Docs/blob/master/pinouts/esp8266_devkit/esp8266_devkit.pdf
https://acrobotic.com/acr-00018
And here about PIR motion sensors:
https://cdn-learn.adafruit.com/downloads/pdf/pir-passive-infrared-proximity-motion-sensor.pdf
27.09.2016
I have some internet/Blynk connection problems with the ESP and sensors. Sometimes it works for about 2 hours, then no more messages are visible on Blynk. If I connect only ESP8266 board without sensors, it works better. So it seems to be a power issue. I just read that GPIO pins can provide up to 12mA; typical 6mA. I also read that ESP is very sensible to power supply, and that reset pin should be connected to 3,3V etc... So now I'm working on this showstopper....need to solve this first.
25.09.2016
And here another possible variant, with 9V block-battery. Power consumption of ESP dev.board is nominal 80mA, but reaches peaks of 300mA and maybe some more for some ms. So type of sensors and power management (sleep mode/stand by) should be optimized a lot if 9V block battery is in use....but this is just a plan for future.
And here with PIR sensor above µSD card reader, and also a switch to enable SW flashing and debug output over USB:
Finding the best location for all sensors and for µSD card. PIR sensor still missing here...
22.09.2016
Today I implemented scanning for several known SSIDs, which are stored in program. The program scans each SSID and tries to connect for e.g. 10 secs. If no connection possible, it tries the next one. It is possible to add as many SSIDs as needed in the code. I did this because sometimes I want to test the device at other locations e.g. friends home; sometimes with a portable hotspot, and of course most of the time at home.
I also store the last active Wifi connection in EEPROM; so if I restart the device at same location, it starts to scan directly this SSID. After finding Wifi hotspot, it connects to internet and to the Blynk server. Usual connection time is about 5,5 secs after startup (to blynk Server). So after 5,5 secs, I already get first terminal messages on my mobile Blynk app of my iPhone : "Wifi SSID Fritzbox xxxx, connected to Blynk server."
19.09.2016
Today I started with the PCB. I had problems finding the right socket board (Buchsenleiste) for the ESP8266 dev. board, because standard socket connectors are 8mm high, and I needed only 5mm or max 6mm height to fit in the small plastic housing. Of course I also looked for 1 pol. socket board. I found some which are called "precise socket connector", but the problem on this was that the dev.board pins does'nt fit in there; the pins are much more thicker than the holes of the connector... So I decided to use 2 pol. socket connctors. I found some 2x8 pins, RM2,54, 6mm high at Pollin for EUR 0,25 each. As the ESP dev. board has 15 pins on each side, I needed 4 of them. To place two connectors side by side, I needed to drag some plastic on one side of each socket with sandpaper.
Socket connectors soldered for ESP dev. board, temp./humidity sendor and lightmeter-sensor:
Later I placed the components...
Here I need to fill the gap below the sensors... all sensors need to be places as high as possible next to the cover:
15.09.2016
Complete hardware on Protoboard is running here (Status LED blinks each x seconds when data is sent/recorded):
Plastic housing; small and cheap:
Data can be transmitted to a terminal window. Here you can see some status messages, SD card information and also current Google-time from the web. Data is updated every 5 sec.:
Also some line graphics is possible. In this case it shows the lightmeter data [lx]. It was late afternoon, thats why value goes to cero. The peak in the middle is when I turned shortly the light on...;
All sensor values visible here; Temperature, Humidity, Light, Microphone and PIR:
07.09.2016
Concept:
This project consists of a small box ( LxBxH 110mm x 55mm x 21mm ) with a NodeMcu Lua ESP8266 12E Wifi development board and many sensors to monitor any room and provide live information via Internet to a Blynk server (to a mobile device).
History data will also be saved into a ThingSpeak channel and also stored into SD card as CSV file for further analysis etc.
The unit is supplied externally via 5V µUSB power supply. So a 220V/110V power connector is needed next to it.
Further system optimizations and reduction of some sensors could make it possible to work with a 9V block batterie for some days.
My plan is to prepare at least 5 devices to monitor some rooms in the basement (which have lot of humidity sometimes), in the attic, and also one unit outside the house below the roof (protected from water, direct sun, snow, etc) with an external infrared termical sensor to work as cloud sensor (if sky is cloudy, IR-temperature below the clouds is similar to ambient temperature; if no clouds in the sky, then IR-temperature is much more less than ambient temperature).
This way I would be able to determine remotely if it makes sense to do some astrophotography or not... Of course, I also could just go outside and see how it looks like ;-)
Status:
- NodeMcu Lua ESP8266 prepared to work with Arduino IDE v1.6.9
- first test-unit completely build on protoboard
- ESP8266 connects to Wifi network and then to Blynk server
- sensors working: DHT22 (temperature, humidity; more accurate than DHT11), BH1750 (light), PIR, Noise (Electret microphone). Possible other sensors: GAS sensor, LDR, Ultrasonic, Infrared temperature, etc...
- get current time from Internet (google time)
- SD card connected and working (read files, SD.h library)
- Blynk simple test environment on IOs shows current data from all over the world
- got slim & cheap plastic housing with all necessary stuff to make a first prototype. The price in germany is around EUR 30,-, in Asia including delivery around EUR 15,- (cons.: >20 days delivery, quality ?) The price includes 5V µUSB power supply and also a 8 GB µSD card.
- Extended Tiny Encryption Algorithm with 128 bits key was successfully tested for further Wifi connection setup file on SD-card
- ThingSpeak channel was prepared
Next steps:
- change SD-card library from standard SD.h to newer SdFat.h which is more stable and has better functions
- store date, time and sensor data on SD card (online & offline mode)
- use last SD-card entry date and time + millis() to store further data in offline mode (no internet connection)
- push data also into ThingSpeak channel for further history data visualization and analysis
- store triggering of events depending on system boundaries (min, max, delta values) into SD-card
- show event triggering on Blynk widgets (LEDs, terminal, etc)
- design concept of online & offline modus and implement it
- send status & error messages via Blynk-Terminal and also store into SD card
- prepare configuration file on SD card to set system boundaries (min, max, delta values) which should be loaded at startup
- prepare configuration file for internet connection. This file will be encrypted using XTEA algorithm (Extended Tiny Encryption Algorithm) which uses a 128 bit key
Very further steps:
- implement master-slave wifi communication (many slaves provides data to one master)