467 views|0 replies

21

Posts

0

Resources
The OP
 

Digi-Key Follow me 2nd Task Submission - Calendar & Clock (Must-do Task) [Copy link]

 This post was last edited by pildio on 2023-10-24 19:36

To obtain the calendar clock, you can obtain it through a third-party weather platform by applying for an API. After obtaining the relevant JSON data, parse the temperature, weather information and time information from the JSON data. After learning here, I still don’t quite understand how to parse the obtained JSON into data. This test code part refers to the forum friends.

First import the package

import board

import digitalio

import time

import wifi

import os

import ssl

import socketpool

import adafruit_requests

import displayio

from adafruit_display_text import label

from adafruit_bitmap_font import bitmap_font

# 屏幕基础配置

display = board.DISPLAY

# 使用字体

font_file = "fonts/SJxinweibeijian-Regular-21.bdf"

font = bitmap_font.load_font(font_file)

# WiFi连接

wifi.radio.connect(os.getenv("WIFI_SSID"), os.getenv("WIFI_PASSWORD"))

# JSON获取

JSON_URL = "http://t.weather.itboy.net/api/weather/city/"+os.getenv("city")

pool = socketpool.SocketPool(wifi.radio)

requests = adafruit_requests.Session(pool, ssl.create_default_context())

response = requests.get(JSON_URL)

# JSON分析

weather = response.json()

cityInfo = weather['cityInfo']

city_weather = weather['data']

forecast = city_weather['forecast']

dis_str = ""+cityInfo['parent']+' '+cityInfo['city'] +' '+weather['time'][:11] + forecast[0]['week']

dis_str += '\n 空气质量:'+city_weather['quality'] +" " +forecast[0]['type']

dis_str += "\n 最"+forecast[0]['high']+' 最'+forecast[0]['low']

dis_str += "\n 湿度: "+city_weather['shidu']

# 屏幕显示

text_group = displayio.Group(scale=1,x=0,y=0,)

text_area = label.Label(font, text=dis_str, color=0xFFFFFF, x=10, y=25)

text_group.append(text_area) # Subgroup for text scaling

display.show(text_group)

while True:

pass

The results are as follows

This code has a bug and cannot accurately locate the city I am in. I will definitely solve this problem when I have enough time!

This post is from DigiKey Technology Zone
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Featured Posts
Download "DSP Integrated Development Environment CCS Development Guide"

Download "DSP Integrated Development Environment CCS Development Guide"

Detailed explanation of using single chip microcomputer to make electronic clock (transferred)

Circuit Features The electronic clock introduced here has a very simple circuit. It only uses a single-chip 20-pin micro ...

Cypress microcontrollers integrate programmable analog circuits (Figure

Cypress microcontrollers integrate programmable analog circuits (Figure)   Cypress MicroSystems of the United ...

[TI recommended course] #Amplifier design in test and measurement#

//training.eeworld.com.cn/TI/show/course/5700

TMS320DM8148 floating point DSP C674x + ARM Cortex-A8RGMIICAN bus interface

processor 2.1 DM8148 TI TMS320DM8148 is a high-performance embedded 32-bit industrial-grade ARM Cortex-A8+DSP C674x pro ...

Sound detection system

# Sound Detection System##Sound Detection System###The sound detection system is used to capture sound and display the t ...

HP Prime G2 calculator with MicroPython support

Hardware of HP Prime G2: CPU: Cortex A7 @528MHz RAM: 256MB Flash (ROM): 512MB LCD: 320x240-pixel (16-bit color) tou ...

RTD Circuit Design

RTD Circuit Design PT100/1000 meaning Common RTDs are PT100 and PT1000. 100 and 1000 mean that when the temperature is 0 ...

Xiaozhi Science Popularization丨To play with DC-DC circuits, you need to master these

DC-DC is a device that converts electrical energy of one voltage value into electrical energy of another voltage value i ...

What are the roles of ARM in embedded development?

The role of ARM in embedded development is mainly reflected in the following aspects: Architecture advantages : The ARM ...

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list