This is a rather simple project.
Anyway, I just discovered that there's this useful API called COVID API (https://github.com/javieraviles/covidAPI) which can be queried on MicroPython devices (many APIs simply not supported by the urequest module due to SSL-related issues).
Use the following url to query data of a specific country
https://coronavirus-19-api.herokuapp.com/countries/{countryName}
Below is the example JSON data of Taiwan on March 20th:
{
"country":"Taiwan",
"cases":135,
"todayCases":27,
"deaths":2,
"todayDeaths":1,
"recovered":28,
"active":105,
"critical":0,
"casesPerOneMillion":6
}
So now I can simply plugin this device and get latest status quickly. And maybe some of you can use this to remind people how dangerous COVID-19 (coronavirus) actually is. Change the country name in API url and time zone offset and you're good to go.
Here I also utilized some new Python knowledge I get recently:
- There are no main while loop; I use 3 machine.Timer (kind of like coroutines) to update data as well as displaying them. (Since the COVID API data does not include query time, I have to update system time via NTP as well. The formatted time string then would be included in the data dictionary.)
- In the script the clock updates itself every 15 minutes. The COVID-19 data updates every 5 minutes (although that may not really be necessary). Adjust them as you like. The clock should be updated at least once every hour to maintain close enough accuracy.
- The two data query functions are decorated with a WiFi connection monitor function (the board would reboot if it lose connection). Yes, you can use decorators in MicroPython.
The board is a WeMos D1 mini (ESP8266). The driver for MAX7219 4-in-1 LED module is from mcauser (https://github.com/mcauser/micropython-max7219).
- VCC: 3.3V or 5V/Vin (5V would be brighter)
- GND: GND
- DIN: MOSI (D7, GPIO 13)
- CS: D8, GPIO 15
- CLK: SCK (D5, GPIO 14)
Stay safe and hygienic, everyone.
Comments