Showing posts with label CRON. Show all posts
Showing posts with label CRON. Show all posts

Monday, October 19, 2015

Update: Android application to control my ESP devices around the home

I've updated the Homy application that controls my ESP8266 based devices around the house.

So more Smart Plugs has been added, more irrigation controllers (for testing),  temperature and humidity sensors.

At the begging each node is starting as AP with it own embedded web server. I can connect to it
with a browser to it and setup the WiFi network and password ( I am planning to do this also from Homy application). After that node gets rebooted and became part of the network.

At statup Homy connects to the cloud broker ( which is connected to my local one) and request an
update from all devices. In this way knows how many of them are and what types they are, what cron settings thay have and what IP, software version they have etc.



Next to do on devices is OTA.
Next device to build is a chrono thermostat device. It will be able to control a heater based on its predefined cron program and aggregated temperature from sensors. Off course  I will be able to control it from the Homy application around the world.




Wednesday, August 26, 2015

New progress today - ESP8266 has UNIX CRON functionality


I've added a cron functionality to my ESP8266 and is working great.
Now I can send a JSON string with unix like cron command:

{"device_name":"ESP9191919", "type":"my_isp_type", "minute":"22" , "hour":"10", "day_of_month":"26", "month":"7", "day_of_week":"3", "gpio":"14","duration":"20", "skip":"0","status":"1", "action":"add" }

to setup a cron job on a specific GPIO. I need it for my irrigation system that was using a CRON on  a raspberry PI to receive the commands for valves.

My CRON implementation support now the "*" functionality for minute, hour, day_of_month, month and day_of_week. In this version is not supporting the "*/10" functionality but if I will need it I will do it.

So sending once the JSON :

{"device_name":"ESP9191919", "type":"my_isp_type", "minute":"00" , "hour":"22", "day_of_month":"*", "month":"*", "day_of_week":"*", "gpio":"14","duration":"20", "skip":"0","status":"1", "action":"add" }

will start the valve connected to gpio 14 every day at 22:00 for 20 minutes.

If I want to skip this cron 2 days, I need to send the same JSON but with skip value of 2.

Skip value get automatically decremented and when it has the value of 0 the cron will do the job. I've need it this functionality, because finally the ESP will be an autonomous system, getting the data from Internet and from my yard, and will be able to propose me an watering plan ( in first stage to be able to test it) and finally to be able to take decisions by itself.
This is what IoT means. 

If I want to disable this cron job, I need to set the status to "0" so it will be ignored every time.


I could have also added the year as a parameter (have it but not used), but I didn't find any utility for that. But is an easy job to do it.


The important thing is that the cron data is written in the flash so a power down is not affecting the cron functionality.

Writing to flash was minimized so only if is necessary a flash update will be done. 

I've used sector 2 for storing the cron data so I can have like 400 cron jobs for now, which is enough for now. I guess I can squeeze another 1000 records in the other sectors, but for now 400 are enough.

TODO list:


Export data as JSON:
  •   {"cron_data":{"minute":"2","hour":"16",......},{"minute":"15","hour":"9",......},   {"minute":"44","hour":"12",......}, {"minute":"20","hour":"8",......}}    DONE !!!
  • */5 functionality 
  • continuity for cron jobs - if there is a power down during a cron job, continue from where it left.




Wednesday, March 4, 2015

ESP8266 Wireless Wifi Module Develop Board 8266 SDK Development Chip

Other interesting board is this board from Electronic Gadget World, a shop on aliexpress.com.

If you can not find this board you can buy other good development boards like:

1. Development board with ESP8266 module and power supply.
2. Battery operated development board
3. Small form factor development board

The parcel contained one ESP201  an SDK Development board and a DHT11 sensor. No cables or power supply. I've ordered two extra ESP201 so I've replaced the faulty one with a good ESP201.

As you can see in the image there are two USBs. The microUSB located on the top right is just for powering the board. The other usb, a type B USB can be used to power the board, and to write firmware to ESP201 flash. The usb to serial on board is a CH340G chip. My win7 didn't complain about it, I was able to write the flash to ESP201.
The only problem is that the transfer was done at 9600 or less (like 5 minute for 200k), after I've modified in the DeviceManager the speed for the port, the transfer rate was increased. But this happened only once, so I gave up using the CH340G chip for now. I've removed the red jumpers and I used my old Prolific USB/serial.

I'll reinstall the drivers for CH340G chip with this one  later and I'll see if helps.


ESP201 SDK development board

Now let's talk about the connections. As you can see the dev board has:


  • a relay
  • a RGB led
  • a white led ( almost under the RGB led which is above the buzeer)
  • DHT11 
  • buzzer
  • two switched S2 and S3
  • a variable rezistor for ADC ( on the left of relay ) connected to ADC pin.
  • a 5v to 3v3 convertor 
  • a main switch in the right upper corner (this switch is just for ESP201 board I guess, I have the impression that the CH340G is still receiving power even the switch is off).


DIP functionality
On the PCB near the DIP switch there are the values :


  • R - should be the RED led from the RGB connected to the IO15 pin. Putting the R DIP to ON will light RED if the GPIO15 is HIGH.
  • G - GREEN led from RGB led is connected to IO13. Putting the G DIP to ON will light GREEN if the GPIO13 is HIGH.
  • B - BLUE led from RGB led is connected to IO12. Putting the B DIP to ON will light BLUE if the GPIO12 is HIGH
  • W - WHITE led located almost under RGB led is connected to the IO14 pin. Putting HIGH on GPIO14 and DIP switch on ON will light the WHITE led
  • J - relay pin connected to IO16 ( which is always HIGH - I have no idea why . This behavior and the RED led that is not working can be because I have a bad board or the design for all the boards is wrong. Connecting the IO16 to GND (not recommended) will stop the relay, otherwise it will be ON all the time the J DIP pin is ON.
  • B - BUZZER connected to IO5 pin throuch B DIP switch. Having GPIO5 HIGH and B on DIP switch ON will prove that the buzzer is working.
  • K1 - I assume is connected to S2
  • K2 - I assume is connected to S3.


A schematics on a napkin will look like this one:


Napkin schematics :-)

And thanks to Scott Snowden and jwbr from http://www.bpower.nl/ there is a complete schematics of the board.


Wifi Module Develop Board 8266 schematics




On IO4 is connected the DHT11 sensor. I didn't use it because I have a DHT22 which is more accurate.


How to write flash.

1.Power off the board.

2.Keep S2 pressed and power on the board using the switch located in the right top of the board.
3.Now you can write the flash from the ESP201 board.


Conclusions:

It is a very good board, no issues found. If you want a rapid development board you can buy this one.

And the final config will look like in this picture (2 external relays, 2 external LEDs DHT22). Pretty crowded. Breadboard is just for GND.




UPDATE1: See what to do to have access on the GPIO15 ( Red led from RGB) - HERE

UPDATE2: See what to do for controlling the relay connected on the XPD / GPIO16 - HERE

UPDATE3: A IoT plug based on ESP-01 - HERE.   A lawn irrigation IoT based on this board is coming soon.

UPDATE4: Now I have a unix cron functionality on my ESP8266 chips.

UPDATE5: MQTT broker running on ESP8266