1. definition of new function: def suma(a,b): # simple addition ... return(a+b) >>> suma(1,2) 3 2. "built_in sensors" - temperature and magnetic (hall) import esp32 esp32.raw_temperature() 127 def f2c(Fahrenheit): Celsius = (Fahrenheit - 32) * 5.0/9.0 return Celsius f2c(esp32.raw_temperature()) esp32.hall_sensor() 129 esp32.hall_sensor() 976 > magnetic 3. WS led colors from util.octopus import ws, RED ws.color(RED) ws.color((128,0,0)) WHITE = (128,128,128) BLACK = (0,0,0) ws.color(WHITE) ws.color(BLACK) ws.simpleTest() ws.rainbow_cycle() from util.rgb import wheel # number to color wheel(10) (225, 30, 0) wheel(50) (105, 150, 0) from util.rgb import random_color while True: ws.color(random_color()) sleep(0.3) 4. API (Application programming interface) Color from Twitter? Last hashtag: #cheerlights API: http://api.thingspeak.com/channels/1417/field/2/last.txt >> #octopusLAB and #micropython example #cheerlights orange from util.octopus import w w() from examples.twitter_rgb import twitter_rgb ws.color(twitter_rgb()) Bitcoin price? from examples.get_bitcoin import bitcoin_usd price = bitcoin_usd() from api: https://api.coinmarketcap.com/v1/ticker/bitcoin/
5. Display setup() > ios > display7 >> 1 from util.octopus import disp7_init d7 = disp7_init() d7.show(123) 6. clock from util.octopus import * ls("examples") # list subdir. files cat("examples/clock.py") # list code cp("examples/clock.py") # file copy - default to main 7. new bmp280 example from examples.bmp280 import bmp_init bmp = bmp_init() t = bmp.temperature d7.show(t) d7.show(str(t)+"C") def action(temp): if temp > 20: ws.color(RED) else: ws.color(BLUE) Influx: from time import sleep from util.octopus import w from util.database.influxdb import InfluxDB from examples.bmp280 import bmp_init bmp = bmp_init() url = 'https://parallelgarden.surikata.info:8086' influx = InfluxDB(url, 'workshop', 'student', 'octopus19') team = 'pivo' w() while True: t = bmp.temperature p = bmp.pressure influx.write('meteo', {'team': team}, temperature= t, pressure= p) print(t, pressure= p) sleep(10) ----------------------------------- from util.octopus import * cat("examples/workshop-iot1.py")
ESP32
from util.octopus import w
w()
from util.database.influxdb import InfluxDB
influx = InfluxDB(‚https://parallelgarden.surikata.info:8086‘, ‚workshop‘, ‚student‘, ‚octopus19‘)
team = ‚pivo‘
Influx sample:
from util.octopus import w w() from util.database.influxdb import InfluxDB url = 'https://parallelgarden.surikata.info:8086' influx = InfluxDB(url, 'workshop', 'student', 'octopus19') team = 'pivo' influx.write('meteo', {'team': team}, temperature=20, pressure=90000)
Complete
import urequests from time import sleep from bmp280 import BMP280 from util.octopus import i2c_init from util.octopus import w #, web_server w() from util.database.influxdb import InfluxDB i2c = i2c_init(1,100000,-1) bmp = BMP280(i2c) influx = InfluxDB("influx_url", "dbname", "username", "password") influx = InfluxDB("https://parallelgarden.surikata.info:8086", "workshop", "student", "octopus19") u = 'https://parallelgarden.surikata.info:8086/write?db=workshop&u=student&p=octopus19' while True: t = bmp.temperature p = bmp.pressureinflux.write("meteo", {'team':'pivo'}, temperature=t, pressure=p)
sleep(5)