#89 An example app showing a practical use case with the API
Using the Eskom load-shedding API is very straight forward however I have noticed that a lot of people get stuck on the last call where an html document is returned instead of Json data. This can throw a spanner in the works because a developer can’t just get the results as a key value pair… the HTML must be parsed and then put into Json before it can be used effectively.
This parsing process is actually quite easy and jut requires a loop with a bit of regex magic to return the values line by line.
Once the values are returned we can then place them into our own Json object and then do something useful with them like creating a loop which reads the times and compares them to the time on my PC then when the json objects time is 10 minutes away the loop then initiates a shutdown of my fan so that it doesn’t drain my ups battery unnecessarily.
Below I have written a small proof of concept application in C# to help inspire others with their projects.
With the ever growing pains of load-shedding looming over South Africans people have been desperately looking for viable alternative energy and battery powered devices. In my case I needed my remote pepper spray devices to be operational in my laboratory even during extended load-shedding times 4h off with 2h charge times.
I could have purchased added a battery and charging circuit to my existing factory made Sonoff board however that could make the PCB larger and I wanted to build a custom solution instead.
My requirements were WiFi capability, at least 4 relays, li-ion battery powered, battery charger with all the standard protection features and for the device to be powered by 5v from a standard phone charger.
The device must be plugged into the 5v phone charger 24/7, when the electricity goes off the device must continue to operate uninterrupted, when the power comes back on the device must change to the charge state uninterrupted.
The device does not have to send a notification when using battery but it must protect from overcurrent and over-discharge.
While looking for components I came across the ESP8266 PSB 04 module which is basically just the MCU WiFi controller used to switch 4 channels by itself
This was perfect for my application because I am already very familiar with Sonoff devices and in this case I do not mind using the firmware on the esp8266 and the Sonoff application + API software for my automation tasks.
Building around the module was a breeze all I needed was the appropriate relay circuits and a decent charging module.
I ended up creating two prototypes because hey there’s always improvements to be made…
The components I used on my final version 1.1 are as follows:
I tried to make the design as modular as practically possible
There are 3 main parts in the design consisting of a main PCB which contains the battery and relays = complementary components then the WiFi module with buttons and 3.3v regulator is located on a small green PCB and finally the LiPo MH-CD42 module can be secured on the main board via headers.
While constructing I had to use a 1.6mm drill bit for the battery holes and a 1.5mm drill bit for the relay holes. I soldered the SMD AMS1117 reg onto 3 a pin male header for easy through hole placement. The relays and the screw terminals required more attention during drilling and placement of the holes due to their pin layout. I also coated all exposed wires with nail varnish as a make shift solder mask.
I had to add an extra 1000uF capacitor between GND and 5v out of the LiPo module because it would briefly lose power when transferring from USB to battery power