MicroPython Program:Update Coronavirus Disease(COVID-19) Data in Real Time

4.2K1819

Intro: MicroPython Program:Update Coronavirus Disease(COVID-19) Data in Real Time

In the past few weeks, the number of confirmed cases of coronavirus disease (COVID 19) worldwide has exceeded 100,000, and the world health organization (WHO) has declared the new coronavirus pneumonia outbreak to be a global pandemic. I was very worried about this outbreak, and I had to go online every day to check the latest outbreak data, but it was very inconvenient, so I made a project to use MakePython ESP32 to get the latest outbreak data in real-time and display it, and it was very convenient to keep it on my desk for the latest situation.

STEP 1: Supplies

Device:

  • MakePython ESP32
  • lithium battery
  • USB cable
  • Toggle switch

Tool:

  • Foamboard
  • knife
  • Paper box
  • Soldering iron
  • Hot melt glue gun
  • Double-sided tape

MakePython ESP32 is an ESP32 board with an integrated SSD1306 OLED display, you can get it from this link: https://www.makerfabs.com/makepython-esp32.html

Software:

uPyCraft V1.1

Click this link to download uPyCraft IDE for Windows:https://randomnerdtutorials.com/uPyCraftWindows

STEP 2: UPyCraft Direction for Use

Download the Get Started MicroPython ESP32 file, which is detailed in the MicroPython Development Tools section of the file, which will help you download and install the uPyCraft IDE and use it. It also helps you get started with MicroPython programming.

You can get the file from this link:https://www.makerfabs.com/makepython-esp32-starter ...

STEP 3: Connect

  • Connect MakePython ESP32 to PC using a USB cable, Open device manager (Simply search for "device" in the Windows search box). When expanded, the port section should display something like the above. Make a note of the port number, such as COM20 in my case. If no port appears, try downloading the USB drive: https://www.silabs.com/products/development-tools/...
  • Open uPyCraft and click: Tools ->board -> esp32,And then click: Tools -> Serial -> COM20(Your port)

STEP 4: The Code Download

Download the boot.py, ssd1306.py and main.py files. Open and click DownloadAndRun to load it into MakePython ESP32.

STEP 5: Modify the Code

  • Open the boot.py file and change the ssid and password to your local network name and password, so that the module can be connected to WIFI for information after power
ssid = "Makerfabs"
password = "20160704"<br>
  • If you find that your country outbreak information is not displayed, please tell me to add it, or you can modify it by yourself. The method is as follows: open the main.py file, find CountryName[], add your CountryName (need to be translated into Chinese) on it, and change the number in range() to the corresponding number of countries, and run after saving it

STEP 6: Make the Mould

Next, we started to make the shell of our own mold:

Use a knife to cut a small hole in the paper box to place the toggle switch, and a long hole to put the display screen.

STEP 7: Weld

The left pin of the toggle switch is welded to the power input of the MakePython ESP32 module with an electric soldering iron. The positive pole of the lithium battery is connected to the middle of the toggle switch, and the negative pole is connected to the GND of the module.

STEP 8: Assembly

  • Attach the module to the foam board with double-sided adhesive tape and the lithium battery to the other side of the foam board.
  • Attach toggle switch to carton hole and fix with a hot glue gun
  • The paper cover is folded into a cardboard box, the display screen is inserted into the long cardboard box hole, and other parts are put into the cardboard box

STEP 9: Complete

By flipping the switch on the carton, MakePython ESP32 connects to the Internet automatically when powered on, and the screen displays the latest outbreak data information.

STEP 10: Display


Looking at the information on the screen, there are so many people infected with the coronavirus. Hope they get better soon! At the same time, we should protect ourselves, wash our hands frequently and gather less.

15 Comments

What am I doing wrong?

I (2369) network: GOT_IP
I (2649) modsocket: Initializing
Traceback (most recent call last):
File "main.py", line 63, in <module>
File "main.py", line 29, in Display_Country
File "urequests.py", line 32, in json
ValueError: syntax error in JSON
MicroPython v1.12 on 2019-12-20; ESP32 module with ESP32
Type "help()" for more information.



Here's a fix:
....
def display_country():
for i in range(38):
x = CountryName[i]
x = x.encode()
x = ''.join('%{:02x}'.format(b) for b in x)
URL = 'https://lab.isaaclin.cn/nCoV/api/area?&province='+ x
response = urequests.get(URL, headers={"Content-Type":"application/json"},)
if response.status_code == 200:
resp_json = response.json()
response.close()
total = resp_json['results'][0]
date = resp_json['results'][0]['updateTime']
utime.sleep(.2)
.....
Cool, this works with some editing..


def Display_Country():
for i in range(38):
x = CountryName[i]
x = x.encode()
x = ''.join('%{:02x}'.format(b) for b in x)
URL = 'https://lab.isaaclin.cn/nCoV/api/area?&province='+ x
response = urequests.get(URL, headers={"Content-Type":"application/json"},)
if response.status_code == 200:
resp_json = response.json()
response.close()
total = resp_json['results'][0]
date = resp_json['results'][0]['updateTime']
time.sleep_ms(200)

.... then the rest of the code is OK as-is
(the next line is "Time_Epoch = 946656000000" )


THANK YOU!
Try to use the micro's libs as much as you can (the onces leading with u). To list them, just type help('modules') on your chip's console.
I’m having exactly the same problem as you are. Hopefully a clever person can tell us where the problem is and how we can fix it!?!
Yeah, I tried a couple different JSON handlers in immediate mode and they all returned the same error.
I think it is related to the UNI code in the URL.
??
Sorry for the trouble, I will update the code later
Same here (ESP32-OLED) however, works on my PC.

import requests
import time
from datetime import datetime

# Add country name
CountryName = ['意大利', '伊朗', '韩国', '法国', '西班牙', '德国', '日本', '美国', '挪威', '瑞士', '丹麦', '荷兰', '瑞典', '英国', '比利时', '卡塔尔', '奥地利', '巴林', '新加坡', '马来西亚', '澳大利亚', '加拿大', '希腊', '冰岛', '以色列', '芬兰', '捷克', '斯洛文尼亚', '阿联酋', '伊拉克', '科威特', '埃及', '巴西', '印度', '爱尔兰', '泰国', '葡萄牙', '俄罗斯']

def display_country():
for i in range(38):
get_url = 'https://lab.isaaclin.cn/nCoV/api/area?&province=' + CountryName[i] _response = requests.get(get_url, headers={"Content-Type": "application/json"}, ) resp_json = _response.json() _response.close()
total = resp_json['results'][0]
#date = resp_json['results'][0]['updateTime']
time.sleep(.2)
x = time.localtime()
update_time = '{}-{:0>2d}-{:0>2d} '.format(x[0], x[1], x[2])

print(str(total['provinceEnglishName']))
print(str('confirmed %d' % (total['confirmedCount'])))
print(str('current %d' % (total['currentConfirmedCount'])))
print(str('cured %d' % (total['curedCount'])))
print(str('dead %d' % (total['deadCount'])))

try:
while True:
display_country()
time.sleep(2)
except KeyboardInterrupt:
pass
do i need the WROOM or the WROVER core on the MakePython ESP32?
Either of these can be used, you can try the WROOM core
I tried you code and I get this error,

I (2927) event: sta ip: 192.168.1.156, mask: 255.255.255.0, gw: 192.168.1.1
I (2927) network: GOT_IP
I (3287) modsocket: Initializing
Traceback (most recent call last):
File "main.py", line 57, in <module>
File "main.py", line 23, in Display_Country
File "urequests.py", line 32, in json
ValueError: syntax error in JSON
MicroPython v1.12-169-gbaf11f237 on 2020-02-16; ESP32 module with ESP32

Just wondering what happened??
Steve
sstocker46@gmail.com
Because of the heavy traffic of the API, starting from March 19, 2020, time-series data are not available on the API anymore. You can get the time-series data directly from the Data Warehouse.
Can i use ESP8266 Wifi Module and Lcd screen instead of EPS32?
(I'm new and this gonna be my first project so sory for my weird question.)