''' Für LoLin - Board Modifiziert von 'Micropython mit ESP32', Lektion 19, WebWetter9.py Erste Test für Kommunikation mit Smartdisplay ''' from netzwerk import * from geheim import * from webseiten import startHTTP, log, hp, wetter from openweathermap import * import time import gc import esp import machine esp.osdebug(None) wifi = WiFi() owm = WetterService(owm_id, owm_lat, owm_lon, owm_ort, owm_land, 600) uart = machine.UART(2, 9600, rx=2, tx=15) def zeit_text(zeit): return datum_zeit_text(owm.get_zeit_lokal(zeit)) def zeige_taeglich(): wetter.add("Tägliche Entwicklung") for w in taeglich: datum = datum_text(owm.get_zeit_lokal(w.get("dt"))) temp = w.get("temp").get("day")
#This file is executed on every boot (including wake-boot from deepsleep) import esp esp.osdebug(None) #this disable debug output import gc def do_connect(ssid,password): import network station = network.WLAN(network.STA_IF) station.active(True) if not station.isconnected(): print('connecting to network...') station.connect(ssid,password) while not station.isconnected(): pass print('network config:', station.ifconfig()) do_connect('reshu','@#caribcolz123$%') import webrepl webrepl.start() gc.collect()
def no_debug(): import esp # you can run this from the REPL as well esp.osdebug(None)
def no_debug(): import esp esp.osdebug(None)
import network import dht import machine import time #import urequests import gc import urandom #import micropython from umqtt.simple import MQTTClient import esp esp.osdebug(False) class SrruIoT(object): def __init__(self,_id,client,bssid,bssid_pass): gc.enable() self.pms = machine.UART(2) self.pms.init(9600,bits=8,parity=None,stop=1) self.dhs = dht.DHT22(machine.Pin(4)) self.station_id = _id self.CFG_BSSID=bssid self.CFG_BSSID_PASS=bssid_pass self.START=time.ticks_ms() self.MQTT = MQTTClient(client,"mqtt.srru.ac.th",1883,"miot","SrruMIoT@2019") def do_connect(self): wlan = network.WLAN(network.STA_IF) wlan.active(True)
print('boot.py') # noqa isort:skip import gc import sys import esp import micropython import utime for no in range(2, 0, -1): print('%i boot.py wait...' % no) utime.sleep(1) esp.osdebug(None) # turn off vendor O/S debugging messages esp.sleep_type(esp.SLEEP_NONE) # Don't go into sleep mode micropython.alloc_emergency_exception_buf(128) gc.enable() # https://forum.micropython.org/viewtopic.php?f=2&t=7345&p=42390#p42390 gc.threshold(8192) # default is: # sys.path=['', '/lib', '/'] # But we would like to be possible to overwrite frozen modues with .mpy on flash drive ;) sys.path.insert(0, '.') print('sys.path=%r' % sys.path) print('boot.py END')
import esp print(esp.check_fw()) except: return # os.listdir() # show_file('boot.py') show_fw() # i2c = I2C(1,scl=) # 以下代码来自http://docs.micropython.org/en/latest/esp8266/quickref.html machine.freq(160000000) machine.freq() esp.osdebug(None) # turn off vendor O/S debugging messages esp.osdebug(0) # redirect vendor O/S debugging messages to UART(0) time.sleep(1) # sleep for 1 second time.sleep_ms(500) # sleep for 500 milliseconds time.sleep_us(10) # sleep for 10 microseconds start = time.ticks_ms() # get millisecond counter delta = time.ticks_diff(time.ticks_ms(), start) # compute time difference # 计时器 # 支持虚拟(基于RTOS)计时器。使用计时器ID为-1 的machine.Timer类: tim = Timer(-1) tim.init(period=5000, mode=Timer.ONE_SHOT, callback=lambda t: print(1)) tim.init(period=2000, mode=Timer.PERIODIC, callback=lambda t: print(2)) # 周期以毫秒为单位。
def no_debug(): esp.osdebug(None)
import esp; esp.osdebug(None) import gc from utils import wifi from utils.pins import LED, ON wifi.toggle_wifi(False) wifi.toggle_hotspot(True) LED.value(ON) gc.collect()
# This file is executed on every boot (including wake-boot from deepsleep) import esp esp.osdebug(None) import gc #import webrepl #webrepl.start() gc.collect()
def initi(): esp.osdebug(None) #no debug gc.collect() #garbage collector
# This file is executed on every boot (including wake-boot from deepsleep) import esp esp.osdebug(None) #redirect vendor O/S debugging messages to UART(0) 0 or None import uos, machine #uos.dupterm(None, 1) # disable REPL on UART(0) import gc import webrepl webrepl.start() gc.collect() # setup WiFi connection # import wifi_connection # wifi_connection.do_connect() # import _thread # import script # script.transit() # Pivot # _thread.start_new_thread(script.detection, ()) # _thread.start_new_thread(script.scan, ()) # script.detection() # car detection # multitask.schedular() # test threading
# 11/10/18 !! import esp, machine, gc gc.enable() esp.osdebug(-1) machine.freq(10**7 * 16)
# This file is executed on every boot (including wake-boot from deepsleep) import esp import utils import gc esp.osdebug(None) utils.do_connect() gc.collect()
try: import usocket as socket except: import socket #sockjet bağalntısı için from machine import Pin import network # network import esp #esp32 veyahut esp8266 için esp.osdebug(None) # her ikisini kullanmak istoyorsak none giriceğiz import gc #gc den hafıza birimini silmek istiyorsak gc.collect() ssid = "TTNET_HUAWEI_9207" #wifiadi password = "******" #wifi şifersi station = network.WLAN(network.STA_IF) #istasyon kurmak için station.active(True) #istasyonu aktif etmek station.connect(ssid, password) #wifi ye bağlantı yap #wifi ye bağlanmamıs gerekli işleri yap while station.isconnected() == False: print("Bağlantı Tamamlanmadı") pass print("Bağlantı Tamamlandı") print(station.ifconfig()) #lçocal de ki ip yi çek #çıkış tanımlıyoruz
v_usb_sample_sum = 0 await asyncio.sleep(0) # # TODO add User Interface, likely using setup screens driven by buttons # # streetsense debugging uses logging module in micropython-lib # levels: DEBUG, INFO, WARNING, ERROR, CRITICAL logging.basicConfig(level=logging.INFO) log = logging.getLogger('streetsense') # general purpose debugging log.setLevel(logging.INFO) logmic = logging.getLogger('streetsense:MIC') # microphone specific debug subsystem logmic.setLevel(logging.INFO) # debugging for other modules esp.osdebug(esp.LOG_ERROR) pms5003.set_debug(False) asyncio.set_debug(False) asyncio.core.set_debug(False) MQTTClient.DEBUG = False operating_mode = NORMAL_MODE log.info('Reset Cause = %d', machine.reset_cause()) i2c = I2C(scl=Pin(26), sda=Pin(27)) ds3231 = urtc.DS3231(i2c, address=0x68) adc = ADS1219(i2c, address=0x41) temp_humid_sensor = si7021.Si7021(i2c) timestamp_unix = None # TODO implement without using a global
Author: Aslak Einbu, Jan 2020 """ # ------------------------- HOOKUP ------------------------------------------------------------------ import config import utime import wifi import webserver import gc import esp utime.sleep(2) # Digesting time for imports gc.enable() # Enable RAM management. gc.collect() # Collecting garbage RAM. esp.osdebug(config.esp_osdebug) # Setting ESP debug setting from config. # Appending provisioned SSIDs with password to stored networks and attempts to connect. wifi.add_provisioned_networks() if not wifi.wlan_sta.isconnected(): wifi.scan_networks() # Scanning for wifi networks. # Attempts connection to stored wifi networks. Broadcasts accesspoint webserver if no success. if not wifi.connect_to_known_network(): server_socket = webserver.ap_webserver_start() while not wifi.wlan_sta.isconnected(): webserver.ap_webserver_loop(server_socket) webserver.ap_webserver_stop(server_socket)
# This file is executed on every boot (including wake-boot from deepsleep) import esp esp.osdebug(None) #must do this if you want to add files to the board import uos, machine # import the uos (needed to add and remove files on the board) #uos.dupterm(None, 1) # disable REPL on UART(0) import gc #import webrepl #webrepl.start() gc.collect()
def __init__(self): esp.osdebug(None) self.wlan = network.WLAN(network.STA_IF)
def setup(): mainOctopus() print("Hello, this will help you initialize your ESP") print("ver: " + ver + " (c)octopusLAB") print("Press Ctrl+C to abort") # TODO improve this # prepare directory if 'config' not in uos.listdir(): uos.mkdir('config') run = True while run: sele = setupMenu() if sele == "q": print("Setup - quit >") time.sleep_ms(1000) print("all OK, press CTRL+D to soft reboot") run = False if sele == "si": #system_info() from util.sys_info import sys_info sys_info() if sele == "ds": print("Device setting:") print(" board_type | soc_type (system on the board)") i = 0 for di in devices: print(str(i) + ": " + str(di[0]) + " | " + str(di[1])) i = i + 1 print() sd = input("select: ") #print(str(devices[int(sd)])) print("> " + str(devices[int(sd)][0]) + " | " + str(devices[int(sd)][1])) dc = {} dc['board_type'] = str( devices[int(sd)][0] ) #input("Board type ('oLAB RobotBoard1' or 'oLAB IoTBoard1'): ") dc['soc_type'] = str(devices[int( sd)][1]) #input("SoC type ('esp32' or 'esp8266'): ") print("Writing to file config/device.json") with open('config/device.json', 'w') as f: ujson.dump(dc, f) # ujson.dump(wc, f, ensure_ascii=False, indent=4) if sele == "ios": print("I/O setting:") # io menu ioMenu() if sele == "iot": print("Testing I/O") from util import io_test io_test.all() if sele == "w": from util.wifi_connect import WiFiConnect w = WiFiConnect() sel_w = wifiMenu() if sel_w == "a": wifi_ssid = input("SSID: ") wifi_pass = input("PASSWORD: "******"r": wifi_ssid = input("SSID: ") w.remove_network(wifi_ssid) if sel_w == "s": print("Saved wifi networks") for k, v in w.config['networks'].items(): print("SSID: {0}".format(k)) if sele == "cw": print("Connect WiFi >") from util.wifi_connect import WiFiConnect w = WiFiConnect() if w.connect(): print("WiFi: OK") else: print("WiFi: Connect error, check configuration") if sele == "cl": print("Connect LAN >") import network lan = network.LAN(mdc=machine.Pin(23), mdio=machine.Pin(18), phy_type=network.PHY_LAN8720, phy_addr=1, clock_mode=network.ETH_CLOCK_GPIO17_OUT) lan.active(1) retry = 0 while not lan.isconnected() or lan.ifconfig()[0] is '0.0.0.0': retry += 1 time.sleep_ms(500) if retry > 20: break if lan.isconnected(): print("LAN: OK") else: print("LAN: Connect error, check cable or DHCP server") if sele == "mq": print("mqtt setup >") try: print() from util.mqtt import mqtt mqtt() except: print("Err.mqtt() or 'util.mqtt.py' does not exist") if sele == "st": print("Time setting >") rtc = machine.RTC() print(str(rtc.datetime())) setdatetime = input( "input 6 numbers - format: RRRRR,M,D,wd,h,m > ") + (",0,0") dt_str = setdatetime.split(",") print(str(dt_str)) dt_int = [int(numeric_string) for numeric_string in dt_str] rtc.init(dt_int) print(str(rtc.datetime())) if sele == "sd": shutil() deplUrl = "https://octopusengine.org/download/micropython/stable.tar" deploy(deplUrl) if sele == "sde": shutil() deplUrl = "https://octopusengine.org/download/micropython/examples.tar" deploy(deplUrl) if sele == "sdp": shutil() deplUrl = "http://iot.petrkr.net/olab/latest.tar" deploy(deplUrl) if sele == "sdo": shutil() deplUrl = "https://octopusengine.org/download/latest.tar" deploy(deplUrl) if sele == "sdh": shutil() deplUrl = "https://octopusengine.org/download/hydroponics.tar" deploy(deplUrl) if sele == "wr": print("under reconstruction <") import esp esp.osdebug(None) import webrepl webrepl.start()
""" import micropython import network import uselect import usocket import time import ntptime from umqtt.simple import MQTTClient from ubinascii import hexlify import machine from esp import osdebug import ujson import gc osdebug(None) gc.collect() import config as C # Status array S = { 'check_fail_count': 0, 'check_first_fail': 0, 'check_last_success': 0, 'client_id': hexlify(machine.unique_id()), 'current_time': 0, 'ip_address': "", 'mem_free': 0, 'net_status': 0, 'relay_change_time': 0, 'relay_status': 1,
from connect import Connect
def no_debug(): import esp # this can be run from the REPL as well esp.osdebug(None)
def log(): import machine, utime, esp, esp32, urequests, usocket, network, uos import bme280, ms5803, post_to_google_sheet from machine import Pin led = Pin(5, Pin.OUT) led.value(0) def flash(n, t): for i in range(n): led.value(1) utime.sleep(t) led.value(0) utime.sleep(t) esp.osdebug(None) startticks = utime.ticks_ms() #declare global login variables ssid = "Sensors" password = "******" gKey = "AKfycbwAJbCuZfNzar00oHPd3CZ8Hzn9c79LfUU5lg8u0p9kAxiGyetqGqWJ" gSheetKey = "1AIWnPTtGNdlZ1TfbzpGTnheCOrPnKUHLUVefa8i2Y8k" wake_reason = machine.wake_reason() reset_cause = machine.reset_cause() print('wake reason = ' + str(wake_reason)) print('reset cause = ' + str(reset_cause)) #mount SD card on Lolin D32 Pro. If it doesn't work, sleep 20 seconds so user can break out. try: uos.mount( machine.SDCard(slot=2, width=1, sck=18, mosi=23, miso=19, cs=4), "/sd") except: flash(20, 0.25) #write header file if did not wake from deep sleep if machine.reset_cause != machine.DEEPSLEEP_RESET: outputtxt = 'date,time,Patm(mbar),Tatm(C),PH20(mbar),TH20(C),Depth(m),Battery(V)\r\n' try: uos.chdir('sd') f = open('datalog.txt', 'a') f.write(outputtxt) f.close() uos.chdir('/') except: #flash LED if fails to write and write to flash memory f = open('datalog.txt', 'a') f.write(outputtxt) f.close() flash(10, 0.5) #turn on power pins for RTC power = Pin(2, Pin.OUT) power.value(1) #connect to wlan try: sta_if = network.WLAN( network.STA_IF) #define object to access station mode functions sta_if.active(True) #make station mode active sta_if.connect(ssid, password) print('connected') except: print('not connected') pass utime.sleep(3) #read value of time from DS3231 RTC if it is connected. If not, set time from #web (NTP time) and if that doesn't work, just revert to system real time clock. try: import urtc #needs to be on the board from machine import I2C, Pin i2c = I2C(scl=Pin(22), sda=Pin(21), freq=400000) rtc = urtc.DS3231(i2c) datetime = rtc.datetime() print('Time set from DS3231') except: try: from ntptime import settime print('Time set from NTP time to: ', end='') settime() utime.sleep_ms(500) rtc = machine.RTC() #can also set time manually using rtc.datetime(year, month, day, weekday, hour, minute, second, millisecond) except: print( "could not set time from NTP server, reverting to machine RTC for time" ) rtc = machine.RTC() datetime = rtc.datetime() print('Datetime in machine.rtc format = ', end='') print(datetime) #read value of voltage using built-in 100k 100k voltage divider on pin 35 for Lolin D32 Pro from machine import ADC adc = ADC(Pin(35)) adc.atten(ADC.ATTN_11DB) #Voltage range 0 (0) V to 3.6 V (4095) adc_count = adc.read() battery = adc_count / 4095 * 3.6 * 2 #factor of two because of voltage divider print('battery = ', battery) #Read data i2c = machine.I2C(1, scl=machine.Pin(22), sda=machine.Pin(21)) bad = False try: bme1 = bme280.BME280(i2c=i2c, address=119) #sdo to 3.3v [T1, P1, H1] = bme1.raw_values #T in degrees C, P in hPa except: [T1, P1, H1] = [-999, -999, -999] bad = True try: [P2, T2] = ms5803.read(i2c=i2c, address=118) except: [P2, T2] = [-999, -999] bad = True if not bad: WaterLevelDifference = (P2 - P1) * 100 / 9810 else: WaterLevelDifference = -999 data = {} data['Patm'] = P1 data['Tatm'] = T1 data['PH20'] = P2 data['TH20'] = T2 data['Depth'] = WaterLevelDifference data['Battery'] = battery #Send data to Google Sheet result = post_to_google_sheet.send_to_sheet(ssid, password, gKey, gSheetKey, data) print(result) #turn off wifi to lower power when in sleep mode sta_if.active(0) #format output string outputtxt = ('%s/%s/%s,%s:%s:%s,' % (datetime[0], datetime[1], datetime[2], datetime[4], datetime[5], datetime[6])) outputtxt += ('%s,%s,%s,%s,%s,%s\r\n' % (P1, T1, P2, T2, WaterLevelDifference, battery)) print(outputtxt) #then write final data to the SD try: uos.chdir('sd') f = open('datalog.txt', 'w') #this erases the old file f.write(outputtxt) #only first line of file is used f.close() uos.chdir('/') except: #flash LED if fails to write and write to flash memory f = open('datalog.txt', 'a') f.write(outputtxt) f.close() flash(10, 0.5) flash(5, 1) p1 = machine.Pin(15, machine.Pin.IN, machine.Pin.PULL_UP) #esp32.wake_on_ext0(p1, level = 0) #set machine to wake if p1 (so pin 15) is pulled low #the internal pull-up resistor may not work, so may require #an external pull-up resistor of perhaps 100K. esp32.wake_on_ext1([p1], level=0) timeon = (utime.ticks_ms() - startticks) / 1000 print('Going to sleep after being awake for ' + str(timeon) + ' s') machine.deepsleep(1000 * 1 * 60) #sleeps 5 minutes
# This file is executed on every boot (including wake-boot from deepsleep) import esp esp.osdebug(0) import gc import webrepl webrepl.start() gc.collect() print('start') '''def do_connect(): import network wlan = network.WLAN(network.STA_IF) wlan.active(True) if not wlan.isconnected(): print('connecting to network...') wlan.connect('LIT', 'l17@2017') while not wlan.isconnected(): pass print('network config:', wlan.ifconfig()) do_collect()'''
from esp import osdebug osdebug(False) def do_connect(): import network sta_if = network.WLAN(network.STA_IF) if not sta_if.isconnected(): print('connecting to network...') sta_if.active(True) sta_if.connect('Opal', 'Indig01234') while not sta_if.isconnected(): pass return sta_if.ifconfig()
# Yet another boot.py for Micropython # # the external file "wifi.json" should state the ssid and password. # Sample "wifi.json": {"ssid":"someSSID","password":"******"} # # Missing wifi.json => no wifi connection # import gc import time import json import network import esp from machine import Pin esp.osdebug(None) # for esp8266 retro compat gc.enable() LEDPIN = 2 # Adjust to your board WIFI_CONFIGFILE = "wifi.json" led = Pin(LEDPIN, Pin.OUT) def successBlink(): for i in range(0, 6): led.value(i % 2 == 0) time.sleep_ms(60) def connectToWifi(): print("Connecting to wifi...") try:
import webrepl from connect import Connect from helpers import Helpers import esp esp.osdebug(None) import gc gc.collect() webrepl.start() try: print(Helpers.free_space()) Connect.connect() except: pass
import usocket as socket import _thread as th import camera import time from time import sleep import esp from machine import Pin import gc from structure import wifi # esp.osdebug(False) esp.osdebug(True) red = ("\033[1;31;40m") green = ("\033[1;32;40m") yellow = ("\033[1;33;40m") blue = ("\033[1;34;40m") normal = ("\033[0;37;40m") hdr = { # start page for streaming # URL: /apikey/webcam 'live': """HTTP/1.1 200 OK Content-Type: text/html; charset=utf-8 <html> <head> <title>Web Camera</title> </head> <body> <center>
import time from umqttsimple import MQTTClient import ubinascii import machine import micropython import network import esp import gc esp.osdebug(None) gc.collect() #setup connection ssid = 'BootCamp-02' password = '******' station = network.WLAN(network.STA_IF) station.active(True) station.connect(ssid, password) while station.isconnected() == False: pass print('Connection successful') print(station.ifconfig()) #setup mqtt server mqtt_server = '192.168.0.178' client_id = ubinascii.hexlify(machine.unique_id()) topic_sub = b'topic/cahaya' topic_pub = b'topic/lampu' last_message = 0 message_interval = 3 counter = 0
# Complete project details at https://RandomNerdTutorials.com import machine from machine import Pin, I2C import BME280 import network import urequests from time import sleep import esp esp.osdebug(None) import gc gc.collect() ssid = 'REPLACE_WITH_YOUR_SSID' password = '******' api_key = 'REPLACE_WITH_YOUR_IFTTT_API_KEY' ms_sleep_time = 600000 station = network.WLAN(network.STA_IF) station.active(True) station.connect(ssid, password) while station.isconnected() == False: pass print('Connection successful')
def disable_debug(): esp.osdebug(None)