iot:micropython
Dies ist eine alte Version des Dokuments!
MicroPython
MicroPython für ESP8266 / ESP32
Blink LED:
from machine import Pin from time import sleep led = Pin(2, Pin.OUT) # sets PIN 2 as Output (most boards have an LED connected) while True: led.value(not led.value()) # toggle LED status sleep(0.25)
MQTT auf dem ESP32:
import network from umqtt.robust import MQTTClient sta_if = network.WLAN(network.STA_IF) sta_if.active(True) sta_if.connect('<YOUR SSID>', '<YOUR PASSWORD>') client = MQTTClient('<CLIENT-ID>', '<BROKER>') client.connect() client.publish('<TOPIC>', '<BYTE_STRING>')
DHT11/22 (ESP32)
from machine import Pin from time import sleep import dht PIN_NR = # define your PIN # here sensor = dht.DHT22(Pin(PIN_NR)) while True: try: sensor.measure() temp = sensor.temperature() hum = sensor.humidity() if (isinstance(temp, float) and isinstance(hum, float)) or (isinstance(temp, int) and isinstance(hum, int)): msg = (b'{0:3.1f},{1:3.1f}'.format(temp, hum)) print(msg) except OSError as e: return('Failed to read sensor.') sleep 2
MicroPython to AWS-IOT
Enthaltene Module (ESP32)
help('modules') __main__ framebuf socket upip _boot gc ssl upip_utarfile _onewire hashlib struct upysh _thread heapq sys urandom _webrepl inisetup time ure apa106 io ubinascii urequests array json ucollections uselect binascii machine ucryptolib usocket btree math uctypes ussl builtins micropython uerrno ustruct cmath neopixel uhashlib utime collections network uhashlib utimeq dht ntptime uheapq uzlib ds18x20 onewire uio webrepl errno os ujson webrepl_setup esp random umqtt/robust websocket esp32 re umqtt/simple websocket_helper flashbdev select uos zlib
iot/micropython.1571020963.txt.gz · Zuletzt geändert: 2019/10/14 02:42 von admin