Compare commits

..

1 Commits

Author SHA1 Message Date
bf604c5e30 added to readme and created dev branch 2021-05-28 13:19:01 +12:00
5 changed files with 52 additions and 27 deletions

1
.gitignore vendored
View File

@@ -1,2 +1 @@
data/ data/
config.json

View File

@@ -1,11 +1,11 @@
# Datalogger # datalogger
ESP8266 running Micropython collecting temperature humidity and light level. Pushing data to a Mosquito server. A python script to ingest the data into an influx database. Grafana to display the data. ESP8266 running Micropython collecting temperature humidity and light level. Pushing data to a Mosquito server. A python script to ingest the data into an influx database. Grafana to display the data.
## Install tools ## Setting up ampy
```pip3 install esptool adafruit-ampy``` `ampy` is a application that allows terminal access to connected micropython devices.
## Download Esp8266 Firmware ## typology
https://micropython.org/resources/firmware/esp8266-20210418-v1.15.bin ![](docs/typology)

View File

Before

Width:  |  Height:  |  Size: 365 KiB

After

Width:  |  Height:  |  Size: 365 KiB

View File

@@ -2,37 +2,26 @@ from machine import Pin
from time import sleep from time import sleep
import machine import machine
import dht import dht
from umqtt.robust import MQTTClient from umqtt.simple import MQTTClient
import json import json
import gc import gc
with open("config.json", 'r') as f:
config = json.load(f)
print(config)
led = Pin(2, Pin.OUT) led = Pin(2, Pin.OUT)
d = dht.DHT11(Pin(12)) d = dht.DHT11(Pin(16))
adc = machine.ADC(0) adc = machine.ADC(0)
server="10.1.1.162"
c = MQTTClient("umqtt_client", config["mqtt"]["server"],ssl=True, user=config["mqtt"]["user"], password=config["mqtt"]["password"]) c = MQTTClient("umqtt_client", server)
gc.enable() gc.enable()
while True: while True:
led(0) led(0)
d.measure() d.measure()
data = {'temp': d.temperature(), 'humid': d.humidity(),'light': adc.read(), 'id': config["id"]} data = {'temp': d.temperature(), 'humid': d.humidity(),'light': adc.read(), 'id': 1}
print(data) print(data)
led(1) led(1)
try: c.connect()
c.connect() c.publish(b"sensors", json.dumps(data))
c.publish(b"sensors", json.dumps(data)) c.disconnect()
finally:
c.disconnect()
gc.collect() gc.collect()
sleep(2)

37
uP/mqtt.py Normal file
View File

@@ -0,0 +1,37 @@
from machine import Pin
from time import sleep
import machine
import dht
from umqtt.robust import MQTTClient
import json
import gc
with open("config.json", 'r') as f:
config = json.load(f)
print(config)
led = Pin(2, Pin.OUT)
d = dht.DHT11(Pin(12))
adc = machine.ADC(0)
c = MQTTClient("umqtt_client", config["mqtt"]["server"],ssl=True, user=config["mqtt"]["user"], password=config["mqtt"]["password"])
gc.enable()
while True:
led(0)
d.measure()
data = {'temp': d.temperature(), 'humid': d.humidity(),'light': adc.read(), 'id': config["id"]}
print(data)
led(1)
c.connect()
c.publish(b"sensors", json.dumps(data))
c.disconnect()
gc.collect()
# wdt.feed()
#sleep(1)