Saravanan666/pypi-org huggingface dataset:
Package: micropython-tziot
海萤物联网教程：MicroPython SDK本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明.欢迎前往社区交流：海萤物联网社区在线文档地址简介海萤物联网的MicroPython SDK是标准Python SDK移植到MicroPython的版本，标准版本可以查看文档：海萤物联网教程：Python SDKMicroPython版本SDK在esp32中测试成功，esp8266资源太少不能运行。本文主要介绍MicroPython版本与标准版本的不同之处。开源github上的项目地址gitee上的项目地址安装MicroPython版本的SDK已上传到pypi，包名是mciropython-tziot。此包依赖micropython-lagan，crcmodbus等若干个包。所以可以新建需求文件，然后一键全部下载。新建文件requirements.txt，内容：micropython-tziot
micropython-lagan
micropython-dcompy
crcmodbus
knocky
sbc
utzpy输入命令下载包到指定目录：pip install --target=d:/package -r requirements.txt下载后文件如下图：删除掉egg-info等无关文件，将所有文件夹都上传到设备的lib目录下，即可在设备中使用。APIMicroPython版本的SDK和标准版本的API接口全部一致，新增了两个函数：defconnect_wifi(ssid:str,key=None,timeout=10)->bool:"""连接wifi:param ssid: wifi热点名:param key: wifi密码.不需要密码则填None:param timeout: 超时时间.单位:s:return: 返回True表示连接成功.False是连接失败"""defrun(app):"""运行应用程序.如果没有应用程序,app可填写None"""connect_wifi：连接wifiesp32等可通过wifi联网的设备，可调用本函数连接wifi。run：运行用户应用程序MicroPython在不同设备上函数嵌套深度各有不同，以esp32为例，主线程的嵌套深度为49，线程中只有10。所以将海萤物联网SDK部署在主线程，然后通过run函数开辟线程运行用户程序。所有用户代码需放在用户程序中。示例读取NTP时间importtziotimporttimepipe=0defmain():globalpipeprint('connect wifi')ok=tziot.connect_wifi('JDHOME_MASTER','QWERASDFZXCV')ifokisFalse:print('connect wifi failed')returnprint('connect wlan success')pipe=tziot.bind_pipe_net(0x2141000000010029,pwd', '0.0.0.0', 12025)tziot.run(app)defapp():globalpipewhilenottziot.is_conn():time.sleep(0.1)resp,err=tziot.call(pipe,0x2141000000000004,1,2000,bytearray())print("err:",err,"time:",resp)if__name__=='__main__':main()输出：connect wifi
connect wlan success
err: 0 time: b'2021-04-06 05:23:00 +0800 CST'对外提供灯控服务开发板上有一个灯，通过GPIO2控制的。对外提供灯控服务，控制这个灯的亮灭。服务号服务1控制灯状态CON请求字段字节数灯状态1ACK应答：空源码：importtziotimporttimefrommachineimportPin# 服务号RID_LED=1pipe=0gpio=Nonestate=Falsedefmain():globalpipe,gpiogpio=Pin(2,Pin.OUT)gpio.on()print('connect wifi')ok=tziot.connect_wifi('JDHOME_MASTER','QWERASDFZXCV')ifokisFalse:print('connect wifi failed')returnprint('connect wlan success')pipe=tziot.bind_pipe_net(0x2141000000010029,pwd,'0.0.0.0',12025)tziot.register(RID_LED,ledService)tziot.run(None)defledService(pipe:int,src_ia:int,req:bytearray)->(bytearray,int):globalstate,gpioiflen(req)!=1:returnprint('src ia:0x%xstate:%d'%(src_ia,req[0]))ifreq[0]:gpio.on()else:gpio.off()returnNone,0if__name__=='__main__':main()用go语言编写一个测试程序控制灯灭然后3秒后亮：pipe,_=tziot.BindPipeNet(0x2141000000000401,pwd,"192.168.1.119",12021)fortziot.IsConn()==false{}resp,err:=tziot.Call(pipe,0x2141000000010029,1,3000,[]uint8{0})fmt.Println("err:",err,"time:",string(resp))time.Sleep(3*time.Second)resp,err=tziot.Call(pipe,0x2141000000010029,1,3000,[]uint8{1})fmt.Println("err:",err,"time:",string(resp))设备LED会灭3秒然后亮，并有打印输出：connect wifi
connect wlan success
src ia:0x2141000000000401 state:0
src ia:0x2141000000000401 state:1
Package: micropython-uaioftp
# micropython-uaioftpLightweight ftp library for MicroPython.## uaioftp server example```import uasyncio as asyncioimport logginglogging.basicConfig(level=logging.DEBUG)#logging.basicConfig(level=logging.INFO)loop = asyncio.get_event_loop()from uaioftp import uaioftpdftpd = uaioftpd(loop=loop, my_ip=netif.ip()[0])loop.call_soon(asyncio.start_server(ftpd.server, "0.0.0.0", 21))try:loop.run_forever()except:loop.close()```
Package: micropython-uaioweb
micropython-uaiowebA very minimal asyncio web framework for MicroPython. Doesn't come with all the bells and whistles you might want out of a serious web framework but the goal is just to make asyncio HTTP applications in MicroPython as simple and efficient as possible.Current featuresminimal overhead in terms of code size or memory useeasy integration into existing asyncio projects by running as a normal task alongside othersbasic endpoint/method based routing similar to flask (currently doesn't do any pattern matching)parses http request line, headers, and query stringssupports WebSockets!supports Server-Sent Events!Rationalemicropython-uaiowebis a packaged version ofmicropython-aioweb, an amazing minimal and functional HTTP toolkit for micropython by Davy Wybiral.This project aims at releasing the library onPyPIby forking and reworking branchmainwith 1 commit per version.ExamplesBasic "Hello world!"importuaiowebfromuaiowebimportasyncio# Note: compatibility between micropython and python.app=uaioweb.App(host='0.0.0.0',port=80)# root route handler@app.route('/')asyncdefhandler(r,w):# write http headersw.write(b'HTTP/1.0 200 OK\r\n')w.write(b'Content-Type: text/html; charset=utf-8\r\n')w.write(b'\r\n')# write page bodyw.write(b'Hello world!')# drain stream bufferawaitw.drain()# Start event loop and create server taskloop=asyncio.get_event_loop()loop.create_task(app.serve())loop.run_forever()POST request handler@app.route('/',methods=['POST'])asyncdefhandler(r,w):body=awaitr.read(1024)form=uaioweb.parse_qs(body.decode())name=form.get('name','world')# write http headersw.write(b'HTTP/1.0 200 OK\r\n')w.write(b'Content-Type: text/html; charset=utf-8\r\n')w.write(b'\r\n')# write page bodyw.write(b'Hello{}!'.format(name))# drain stream bufferawaitw.drain()WebSocket handler# /ws WebSocket route handler@app.route('/ws')asyncdefws_handler(r,w):# upgrade connection to WebSocketws=awaitWebSocket.upgrade(r,w)whileTrue:evt=awaitws.recv()ifevtisNoneorevt['type']=='close':# handle closed stream/close eventbreakelifevt['type']=='text':# print received messages and echo themprint('Received:',evt['data'])awaitws.send(evt['data'])SSE (Server-Sent Events) handler# /events EventSource route handler@app.route('/events')asyncdefws_handler(r,w):# upgrade connection to text/event-streamsse=awaituaioweb.EventSource.upgrade(r,w)count=0whileTrue:count+=1try:awaitsse.send('Hello world #{}'.format(count))except:breakawaitasyncio.sleep(1)
Package: micropython-uAPI
uAPI - A micropython API frameworkThis project is meant to make programming APIs on micropython supported microcontrollers easier. The general design is inspired bytiangolo/fastapi, one of my favorite python frameworks which I personally use a lot.If you have any questions, it is recommended to check theexamples directoryfirst.UsageGenerally there are two possibilities to use this framework in your project:prebuild (recommended):You can go to the releases page and check for the latest .mpy file. You can simply add this file on your controller and it will be used just as the sourcecode itself.source code:You can also add the entireuAPI/subdirectory on your controller and develop with it as with any other local module. This is only recommended if you want to experiment on something or contribute to the project.FeaturesSafe typing for headersBuildingThe two sections below describe how to build the framework either manually or with Docker.ManuallyFirst of all make sure you have the latest version of the mpy-cross, the open source micropython cross compiler. For that visit the officalmicropython github page.Then you can simple aggregate all the python files in theuAPI/subdirectory to a singleuAPI.pyfile which will be stored inbuild/, using the provided scriptcreate_single_file.py.This file can already be used as your module. It is recommended to use the precompiled version though, reducing the space and also the runtime. Therefore simply use the mpy-cross command after merging the files:mpy-cross-O[3]./build/uAPI.py-O[3]will indicate mpy-cross to use the highest level of compression, read more about these in the mpy-cross documentation.Docker(-Compose)To build using the docker compose simply use, (don't forget to add--buildif running the first time):docker-composeupuapi-buildIf you do not want to run with docker-compose but still want to use docker, you can do so by mounting the directories into the image on run:docker build . -t uapi-build
docker run \
    -v $(pwd)/uAPI:/uAPI \
    -v $(pwd)/build:/build \
    uapi-buildContributingThank you for your interest in contributing to this project!Compiling and TestingTo validate whether your changes would compile you can call themicropython unix portfrom the offical repository.You can check your compile by:micropython -X compile-only <your changed file>TODO TESTINGFormattingWe useblackto check our formatting, to use it you can simply install it by (you may need an sudo install to get it as an recognized command in your shell):(sudo) pip3 install blackYou can simply use it asblack .to automatically format the whole project or with the--check --diffflags to see if black would require you to do any changes without actually writing on your files.HooksYou should setup a pre-commit hook on your machine, that handles the format and syntax checks automatically and helps you to keep your worktree clean. Note that not well formatted code (and of course unfunctional one) will not be accepted to the codebase.git config --local core.hooksPath ./.githooks/LicenseThis project is licensed under the terms of the MIT license.
Package: micropython-uctypes
This is a dummy implementation of a module for MicroPython standard library.
It contains zero or very little functionality, and primarily intended to
avoid import errors (using idea that even if an application imports a
module, it may be not using it onevery code path, so may work at least
partially). It is expected that more complete implementation of the module
will be provided later. Please help with the development if you are
interested in this module.
Package: micropython-unicodedata
This is a dummy implementation of a module for MicroPython standard library.
It contains zero or very little functionality, and primarily intended to
avoid import errors (using idea that even if an application imports a
module, it may be not using it onevery code path, so may work at least
partially). It is expected that more complete implementation of the module
will be provided later. Please help with the development if you are
interested in this module.
Package: micropython-unix-stubs
micropython-unix-stubsThis is a stub-only package for MicroPython.
It is intended to be installed in a projects virtual environment to allow static type checkers and intellisense features to be used while writing Micropython code.The version of this package is alligned the the version of the MicroPython firmware.Major, Minor and Patch levels are alligned to the same version as the firmware.The post release level is used to publish new releases of the stubs.ForMicropython 1.17the stubs are published as1.17.post1...1.17.post2forMicropython 1.18the stubs are published as1.18.post1...1.18.post2To install the latest stubs:pip install -I  micropython-<port>-stubswhere port is the port of the MicroPython firmware.To install the stubs for an older version, such as MicroPython 1.17:pip install micropython-stm32-stubs==1.17.*which will install the last post release of the stubs for MicroPython 1.17.As the creation of the stubs, and merging of the different types is still going though improvements, the stub packages are marked as Beta.
To upgrade stubs to the latest stubs for a specific version usepip install micropython-stm32-stubs==1.17.* --upgradeIf you have suggestions or find any issues with the stubs, please report them in theMicroPython-stubs DiscussionsFor an overview of  Micropython Stubs please see:https://micropython-stubs.readthedocs.io/en/main/List of all stubs :https://micropython-stubs.readthedocs.io/en/main/firmware_grp.htmlIncluded stubs:Merged stubs fromstubs/micropython-v1_21_0-unix-GENERIC-mergedFrozen stubs fromstubs/micropython-v1_21_0-frozen/unix/GENERICCore stubs fromstubs/micropython-coreoriginFamilyPortBoardVersionDocumentationmicropython--v1.21.0Coremicropythonunix-v1.21.0
Package: micropython-uPIL
This is a dummy implementation of a module for MicroPython standard library.
It contains zero or very little functionality, and primarily intended to
avoid import errors (using idea that even if an application imports a
module, it may be not using it onevery code path, so may work at least
partially). It is expected that more complete implementation of the module
will be provided later. Please help with the development if you are
interested in this module.
Package: micropython-uploader
## Micropython Uploader### The script can:Recursively bypass the current directoryDownload detected files to mk. It was decided that you should push only.pyfiles.Delete all files with mk (ps directory is also a file)## InstallationOn MacOS or Linux, in a terminal run the following command (assuming
Python 3):pip3 install –user micropython-uploaderOn Windows, do:pip install micropython-uploader## UsageIn terminal run:mploader### Requirements:ampypip3 install ampymicropythonas firmware for microcontroller
Package: micropython-uplot
IntroductionMicroPython Graphics Library. This library uses the IL9486 driver from Peter Hinch taken fromhttps://github.com/peterhinch/micropython-nano-gui. with a Waveshare 3.5 display
This library uses FrameBuffer. It could work for other displays, however, is not my intention to
adapt or provide this functionality. This is an exercise to learn MicroPython Graphics adapting
the following library from CircuitPythonhttps://github.com/jposada202020/CircuitPython_uplotTake a look in theexamplessection in RTD to see the galleryInstalling with mipTo install using mpremotempremotemipinstallgithub:jposada202020/MicroPython_UPLOTTo install directly using a WIFI capable boardmip.install("github:jposada202020/MicroPython_UPLOT")Installing Library ExamplesIf you want to install library examples:mpremotemipinstallgithub:jposada202020/MicroPython_UPLOT/examples.jsonTo install directly using a WIFI capable boardmip.install("github:jposada202020/MicroPython_UPLOT/examples.json")Installing from PyPIOn supported GNU/Linux systems like the Raspberry Pi, you can install the driver locallyfrom
PyPI.
To install for current user:pip3installmicropython-uplotTo install system-wide (this may be required in some cases):sudopip3installmicropython-uplotTo install in a virtual environment in your current project:mkdirproject-name&&cdproject-namepython3-mvenv.venvsource.env/bin/activatepip3installmicropython-uplotUsage ExampleTake a look at the examples directoryDocumentationAPI documentation for this library can be found onRead the Docs.
Package: micropython-urequests
micropython-lib currently offers 4 HTTP client modules:urllib.urequesturequestsuurequestsuaiohttpclientThis README is intended to describe differences among them and help
to choose the right module for a particular use.urllib.urequestimplements a subset of API CPython standard library
module urllib.request. This module is intended to be the most minimal
of all three and provide an efficient, stream-based API. It doesn’t
support automatic redirects or chunked transfer encoding.urequestsimplements a subset of API of the popular 3rd-party packagerequests.requestsbrags itself as “HTTP for Humans”, which
means that its API is not ideal, and implementation is inefficient.urequestsimplements only a subset of it, and tries to mend some
poor defaults of the prototype module. Still, it’s less efficient
thanurllib.urequest. Redirects are handled, but not chunked
transfer encoding.uurequestsis capture of the version 0.8 ofurequests, before
opening the door for adding more features to the latter. It’s provided
for very small systems which still would like requests-like API.uaiohttpclientis an HTTP client foruasynciomodule. It’s
the only of all 3 which supports chunked transfer encoding.Thus, the selection guide:Whenever possible, useurllib.urequest.If you write a once-off, throw-away app where you don’t care about
efficiency, you can useurequests.If you wrote that for very small system and above didn’t work, can
giveuurequestsa try.If you devel an async app, useuaiohttpclient.If you need support for more HTTP protocol features, useuaiohttpclientand write an async app.Future of the modules:urllib.urequestis intended to stay minimal and unlikely will get more
features (it’s suitable for ~80% of possible usage scenarios).urequestshas bloat in its DNA, so likely will slowly grow more features
to match the upstream module, which will make it even less suitable for
low-memory targets.uurequestswas snapshotted to address concern of such low-memory systems
support. It’s static, and only critical bugfixes are intended to be applied.uaiohttpclientmay get updated as needed.
Package: micropython-urequests.auth
This is a dummy implementation of a module for MicroPython standard library.
It contains zero or very little functionality, and primarily intended to
avoid import errors (using idea that even if an application imports a
module, it may be not using it onevery code path, so may work at least
partially). It is expected that more complete implementation of the module
will be provided later. Please help with the development if you are
interested in this module.
Package: micropython-url-encode
micropython-url_encodeThis is a micropython library aimed at encoding and decoding URLs.UsagefromUrl_encodeimporturl_encodesome_api='https://wpmsg.com/?text='string_to_be_url_encoded='This is a message'url=url_encode()encoded_string=url.encode('string_to_be_url_encoded')url_to_be_decoded=some_api+encoded_stringdecoded_url=url.decode(url_to_be_decoded)print('\nThe encoded string is:',encoded_string)print('URL:',some_api+encoded_string)print('\nThe decoded URL is:',decoded_url)OUTPUTTheencodedstringis:string%5fto%5fbe%5furl%5fencodedURL:https://wpmsg.com/?text=string%5fto%5fbe%5furl%5fencodedThedecodedURLis:https://wpmsg.com/?text=string_to_be_url_encoded
Package: micropython-urllib.parse
This is a module ported from CPython standard library to be compatible with
MicroPython interpreter. Usually, this means applying small patches for
features not supported (yet, or at all) in MicroPython. Sometimes, heavier
changes are required. Note that CPython modules are written with availability
of vast resources in mind, and may not work for MicroPython ports with
limited heap. If you are affected by such a case, please help reimplement
the module from scratch.
Package: micropython-urllib.urequest
HTTP clients in micropython-lib===============================micropython-lib currently offers 4 HTTP client modules:* ``urllib.urequest``* ``urequests``* ``uurequests``* ``uaiohttpclient``This README is intended to describe differences among them and helpto choose the right module for a particular use.* ``urllib.urequest`` implements a subset of API CPython standard librarymodule urllib.request. This module is intended to be the most minimalof all three and provide an efficient, stream-based API. It doesn'tsupport automatic redirects or chunked transfer encoding.* ``urequests`` implements a subset of API of the popular 3rd-party package``requests``. ``requests`` brags itself as "HTTP for Humans", whichmeans that its API is not ideal, and implementation is inefficient.``urequests`` implements only a subset of it, and tries to mend somepoor defaults of the prototype module. Still, it's less efficientthan ``urllib.urequest``. Redirects are handled, but not chunkedtransfer encoding.* ``uurequests`` is capture of the version 0.8 of ``urequests``, beforeopening the door for adding more features to the latter. It's providedfor very small systems which still would like requests-like API.* ``uaiohttpclient`` is an HTTP client for ``uasyncio`` module. It'sthe only of all 3 which supports chunked transfer encoding.Thus, the selection guide:* Whenever possible, use ``urllib.urequest``.* If you write a once-off, throw-away app where you don't care aboutefficiency, you can use ``urequests``.* If you wrote that for very small system and above didn't work, cangive ``uurequests`` a try.* If you devel an async app, use ``uaiohttpclient``.* If you need support for more HTTP protocol features, use``uaiohttpclient`` and write an async app.Future of the modules:* ``urllib.urequest`` is intended to stay minimal and unlikely will get morefeatures (it's suitable for ~80% of possible usage scenarios).* ``urequests`` has bloat in its DNA, so likely will slowly grow more featuresto match the upstream module, which will make it even less suitable forlow-memory targets.* ``uurequests`` was snapshotted to address concern of such low-memory systemssupport. It's static, and only critical bugfixes are intended to be applied.*``uaiohttpclient`` may get updated as needed.
Package: micropython-usercustomize
This is a dummy implementation of a module for MicroPython standard library.
It contains zero or very little functionality, and primarily intended to
avoid import errors (using idea that even if an application imports a
module, it may be not using it onevery code path, so may work at least
partially). It is expected that more complete implementation of the module
will be provided later. Please help with the development if you are
interested in this module.
Package: micropython-ustruct
This is a dummy implementation of a module for MicroPython standard library.
It contains zero or very little functionality, and primarily intended to
avoid import errors (using idea that even if an application imports a
module, it may be not using it onevery code path, so may work at least
partially). It is expected that more complete implementation of the module
will be provided later. Please help with the development if you are
interested in this module.
Package: micropython-uu
This is a module ported from CPython standard library to be compatible with
MicroPython interpreter. Usually, this means applying small patches for
features not supported (yet, or at all) in MicroPython. Sometimes, heavier
changes are required. Note that CPython modules are written with availability
of vast resources in mind, and may not work for MicroPython ports with
limited heap. If you are affected by such a case, please help reimplement
the module from scratch.
Package: micropython-uurequests
micropython-lib currently offers 4 HTTP client modules:urllib.urequesturequestsuurequestsuaiohttpclientThis README is intended to describe differences among them and help
to choose the right module for a particular use.urllib.urequestimplements a subset of API CPython standard library
module urllib.request. This module is intended to be the most minimal
of all three and provide an efficient, stream-based API. It doesn’t
support automatic redirects or chunked transfer encoding.urequestsimplements a subset of API of the popular 3rd-party packagerequests.requestsbrags itself as “HTTP for Humans”, which
means that its API is not ideal, and implementation is inefficient.urequestsimplements only a subset of it, and tries to mend some
poor defaults of the prototype module. Still, it’s less efficient
thanurllib.urequest. Redirects are handled, but not chunked
transfer encoding.uurequestsis capture of the version 0.8 ofurequests, before
opening the door for adding more features to the latter. It’s provided
for very small systems which still would like requests-like API.uaiohttpclientis an HTTP client foruasynciomodule. It’s
the only of all 3 which supports chunked transfer encoding.Thus, the selection guide:Whenever possible, useurllib.urequest.If you write a once-off, throw-away app where you don’t care about
efficiency, you can useurequests.If you wrote that for very small system and above didn’t work, can
giveuurequestsa try.If you devel an async app, useuaiohttpclient.If you need support for more HTTP protocol features, useuaiohttpclientand write an async app.Future of the modules:urllib.urequestis intended to stay minimal and unlikely will get more
features (it’s suitable for ~80% of possible usage scenarios).urequestshas bloat in its DNA, so likely will slowly grow more features
to match the upstream module, which will make it even less suitable for
low-memory targets.uurequestswas snapshotted to address concern of such low-memory systems
support. It’s static, and only critical bugfixes are intended to be applied.uaiohttpclientmay get updated as needed.