PyClock

  1. Code structure
  2. Code analysis
    1. Function introduction
    2. Call instructions for service.py and led.py files
  3. How to use
  4. Version description

An ESP32-based micropython project at https://github.com/XU-Zijin/PyClock

This is an open source project, the original project address https://github.com/01studio-lab/pyClock. You can also click here to download directly PyClock, I use the premise of this project is to have the original project of hardware and firmware, I will consider adapting boards without this firmware later.

I rewrote the software part of this open source project (not including firmware)PS: The code level is not high, you can point out directly if you have comments, please point out where there are optimizations and bugs

Code structure

Boot. py: boot parameter Settings

Main.py: main function code

data: Data

|-- Fonts: indicates the font file
|-- picture: indicates the subject picture
|-- CityCode.txt: indicates the national city code
file: Used to store system files
    |-- wifi.txt: records the password of the WiFi account
    |-- mode.txt: indicates the system status file
    |-- set.txt: indicates the system status file

lib: service

|---develop
    |-- devmode.py: Developer mode (not finished)
|---service
    |-- service.py: System service (core)
    |-- led.py: controls led lights
    |-- system.py: for pyshell(to be developed)
    |-- ip.py: automatically obtains the city

libs: Project Micropython library

urllib: urequest library
    |-- urequest.py: crawler library
    |-- ap.py: indicates the AP hotspot network distribution
    |-- global_var.py: global variable definition
ui: UI theme library
    |-- dial.py: indicates a simple table disk
    |-- default.py: indicates the default dial

service.py is the core of the program, where most of the functionality is called

Note: Since the functionality in system.py and devmode.py files is not yet developed or completed, it can be deleted when used without affecting the existing functionality and stability

Code analysis

Structural analysis

First of all, the data folder is used to store the theme picture, font, code and the files required by the system running.

In the lib folder is the devmode.py file for debugging and the service.py file for most of the basic functions of the system, as well as the file for controlling leds, and finally there is a system.py file for planning development. I plan to implement a terminal function on this open source hardware PyClock board, that is, pyshell.

And libs inside is a variety of required libraries, as well as dial, that is, UI.

Function introduction

The main functions of this weather clock:

  • Check the weather
  • Check temperature and humidity
  • Check the time
  • Can breathe screen
  • Dial can be switched
  • Boot automatic calibration time
  • Mobile phone web distribution network
  • Automatically get the city

Call instructions for service.py and led.py files

Use from lib.service import led to call LEd.py, use LEd.on () to turn on the led that comes with the board, use LEd.off () to turn it off.

Use from lib.service.service import server to import the server library

These two lines of code are used for networking

while not server.WIFI_Connect()==True:
pass

server.sync_ntp() is used to synchronize the network clock

server.city_get() gets the city code

city =server.re(city) Returns the city code

datetime = server.re(rtc) Returns the rtc time

server.weather_get(datetime) gets the weather

weather =server.re(weather) Return weather

server.info_print() prints the weather to the debug console

server.check() self-check

How to use

For the first time, follow the steps shown on the screen to configure the network, and then switch to the default astronaut dial, short press to switch the dial, there are two dial, press the two-second pause screen, and long press for 5 seconds to enter the factory Settings.

Version description

V2.0.1 Add automatic adjustment of the esp32 CPU frequency to save power consumption, the CPU frequency is 160MHz under normal conditions, 80MHz during the breath screen, and 20MHz when the breath screen is more than 15 minutes

V2.0.0 Modify the default dial, modify the AP network file, can automatically detect the city, and add two new functions: short press to switch the dial and press the two-second pause screen

V1.0.0 Open source, rewrite the main code (except dial, AP distribution network)


Please indicate the source for reprinting, welcome to research the sources quoted in the article, welcome to point out any errors or not clear expression. Leave a comment in the comment section below or email us at [email protected]

Title:PyClock

Count:684

Author:Xu Zijin

Created At:2024-01-23, 15:30:47

Updated At:2024-03-15, 13:16:48

Url:https://xuzijin.com/en/01232024/PyClock/

Copyright: 'Attribution-non-commercial-shared in the same way 4.0' Reprint please keep the original link and author.

简体中文