micropython

Pin ESP-8266 Pin
TX gpio1 TXD
RX gpio3 RXD
A0 A0 Analog input, max 3.3V input
D0 GPIO16 irq, pwm, I2C
D1 GPIO5 SCL
D2 GPIO4 SDA
D3 GPIO0 10k Pull-up
D4 GPIO2 10k Pull-up, BUILTIN_LED
D5 GPIO14 SCK
D6 GPIO12 MISO
D7 GPIO13 MOSI
D8 GPIO15 10k Pull-down, SS
G Ground GND
5V 5V -
3V3 3.3V 3.3V
RST Reset RST

All of the IO pins have interrupt/pwm/I2C/one-wire support except D0 only pins 0, 2, 4, 5, 12, 13, 14, 15, and 16 can be used

Dateiname: sc.py
Dateiinhalt:
def echo(content)
  print(content)

print("Start bzw. Ausgabe nur bei import sc")
echo("Wird auch beim import ausgeführt. Danach nur über sc.echo() erreichbar")

Also möchte man seine Funktionen auf repl ausführen, sollte man den Dateinamen und Funktionsnamen kennen, damit man jederzeit auf sein Programm zugreifen kann.

Textdatei lesen (schreiben):
f=open("D:\\new_dir\\multiplelines.txt","r")
#Use print to print the line else will remain in buffer and replaced by next statement
for line in f:
    print(line)
f.close()

PLatz auf ESP8266:
==================
import uos
fs_stat = uos.statvfs('/')
fs_size = fs_stat[0] * fs_stat[2]
fs_free = fs_stat[0] * fs_stat[3]
print("File System Size {:,} - Free Space {:,}".format(fs_size, fs_free))

NETZWERK:
=============
import network

wlan = network.WLAN(network.STA_IF) # create station interface
wlan.active(True) # activate the interface
wlan.scan() # scan for access points
wlan.isconnected() # check if the station is connected to an AP
wlan.connect('essid', 'password') # connect to an AP
wlan.config('mac') # get the interface's MAC adddress
wlan.ifconfig() # get the interface's IP/netmask/gw/DNS addresses

ap = network.WLAN(network.AP_IF) # create access-point interface
ap.active(True) # activate the interface
ap.config(essid='ESP-AP') # set the ESSID of the access point

def do_connect():
    import network
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    if not wlan.isconnected():
        print('connecting to network...')
        wlan.connect('essid', 'password')
        while not wlan.isconnected():
            pass
    print('network config:', wlan.ifconfig())

MQTT Mosquitto:
================

mosquitto_pub -h test.mosquitto.org -t dfdfdf -m "Hello Raspberry Pi"
mosquitto_sub -h localhost -v -t test_channel
Client:
Micropython:

kopiere umqtt/simple.py nach /lib/umqtt/

HTTP

#www.http_get('http://9df.de/smarthome/hum1.php?t=20&h=65&r=Keller1')
import socket
def http_get(url): _, _, host, path = url.split('/', 3)  
    addr = socket.getaddrinfo(host, 80)[0][-1]
    s = socket.socket()
    s.connect(addr)
    s.send(bytes('GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n' % (path, host), 'utf8'))
    while True:
        data = s.recv(100)  
        if data:  
            print(str(data, 'utf8'), end='')  
        else:  
            break  
    s.close()
http_get('http://9df.de/smarthome/hum1.php?t=20&h=65&r=Keller1')