Last active
October 9, 2018 07:44
-
-
Save shibacow/2e42663ff68751a22b09792b80437e73 to your computer and use it in GitHub Desktop.
Ambient data logging system that send data to using micropython + bme280 via https://ambidata.io/ ref https://github.com/AmbientDataInc/ESP32SamplePrograms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from machine import I2C, Pin,deepsleep | |
import utime | |
# from m5stack import lcd | |
# see bme280,ambient lib from https://github.com/AmbientDataInc/ESP32SamplePrograms/tree/master/Micropython | |
import bme280 | |
import ambient | |
ssid = 'your_ssid' | |
password = 'your_wifi_password ' | |
channelId = #yourchannel_id via https://ambidata.io/ ,that is integer | |
writeKey = '' #your wirte kye in ambidata.io | |
def do_connect(ssid, password): | |
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(ssid, password) | |
while not sta_if.isconnected(): | |
pass | |
print('network config:', sta_if.ifconfig()) | |
led=Pin(27,Pin.OUT) | |
led.value(1) | |
i2c = I2C(sda=Pin(12, pull=Pin.PULL_UP), scl=Pin(14, pull=Pin.PULL_UP)) | |
bme = bme280.BME280(i2c=i2c) | |
am = ambient.Ambient(channelId, writeKey) | |
do_connect(ssid, password) | |
while True: | |
# lcd.clear() | |
# lcd.print(str(bme.values), 0, 0) | |
data = bme.read_compensated_data() | |
print(bme.values) | |
r = am.send({'d1': data[0] / 100.0, 'd2': data[2] / 1024.0, 'd3': data[1] / 25600.0}) | |
print(r.status_code) | |
r.close() | |
led.value(0) | |
#utime.sleep(60) | |
deepsleep(60*1000) |
BME280とかambientのライブラリはこちらを参考にしました。
https://github.com/AmbientDataInc/ESP32SamplePrograms
参考になりました。
WiFi 接続の部分は boot.py に移しました。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
回路図