Simple mock program to set charging rate of a battery instance based on the national grid intensity api.
Steps to get up and running
I have created two different services, as the spec wasn't very clear as to what they refer to as a "microservice". Although both are very similar in nature, one is a http api that starts a scheduler (
charge-api) and the other one (called
charge) is a simple command line program application that could be run in the background of microcontrollers with an in-build scheduler (
charge), so no need to setup
cron on these microcontrollers (although haven't tested this with Tiny Go so might need a few tweaks to get it to work on microcontrollers).
charge-api is almost identical to
charge except that this has a net/http switch to turn the scheduler on or off using the endpoints
To run both, you can just build them similar to how all go applications are built. For example, to run
charge you can run the following in your terminal (linux or macos)
cd cmd/charge go build . ./charge
charge-api, similary just build and run as before except you should just change directory to cmd/charge-api
cd cmd/charge-api go build . ./charge-api
The usage of
charge is quite simple by design. The idea is very simple (I have assumed a few things because the spec wasn't detailed in terms of the timing of the api national grid api was being used.) The
charge application simply starts a scheduler like ticker, and runs at every half hour interval at hh:00 and hh:30 (roughly.) The logic for this is quite simple, but I wasn't sure if this is what was asked so I created another one because I wasn't sure what their definition of a microservice is.
charge-api on the other hand is
/stop endpoints to start the scheduler similar to
charge. I think there is definitely a lot of things that could be improved in the
charge-api but I didn't have a lot of time to explore other options.
Do let me know if you have any questions!
NOTE: I have profiled
charge extensively to see what the energy impact of this is and for two hours that I kept this running it only took about 7mb of memory and negligible cpu usage, in case this is an important factor.