Skip to content

Instantly share code, notes, and snippets.

@sweemeng
Created May 5, 2019 08:49
Show Gist options
  • Save sweemeng/7acd90b06a6e80cbfa1566da52edb04c to your computer and use it in GitHub Desktop.
Save sweemeng/7acd90b06a6e80cbfa1566da52edb04c to your computer and use it in GitHub Desktop.
m5stack to influxdb
from m5stack import *
from m5ui import *
import time
import struct
import network
import urequests
import ujson
def push_data(button_name):
lcd.clear()
data = "button {button_name}=1".format(button_name=button_name)
urequests.post("http://influxdb_instance/write?u=username&p=passwd&db=mydb", data=data)
lcd.print("button {button_name} is pressed".format(button_name=button_name))
def button_a_pressed():
push_data("button_a")
def button_b_pressed():
push_data("button_b")
f = open("/flash/hazeconf.json")
config = ujson.loads(f.read())
# setup wifi
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(config["ssid"],config["password"])
while not wlan.isconnected():
lcd.clear()
lcd.print("Connecting")
buttonA.wasPressed(button_a_pressed)
buttonB.wasPressed(button_b_pressed)
utime.sleep(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment