Compare commits
4 Commits
03e17428c5
...
b690a86215
Author | SHA1 | Date |
---|---|---|
Jimmy | b690a86215 | |
Jimmy | 091d24a263 | |
Jimmy | 71247d0154 | |
Jimmy | 9ee2603137 |
|
@ -1 +1,2 @@
|
|||
data/
|
||||
data/
|
||||
config.json
|
||||
|
|
12
README.md
12
README.md
|
@ -1,3 +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
|
||||
|
||||
```pip3 install esptool adafruit-ampy```
|
||||
|
||||
## Download Esp8266 Firmware
|
||||
|
||||
https://micropython.org/resources/firmware/esp8266-20210418-v1.15.bin
|
29
uP/main.py
29
uP/main.py
|
@ -2,26 +2,37 @@ from machine import Pin
|
|||
from time import sleep
|
||||
import machine
|
||||
import dht
|
||||
from umqtt.simple import MQTTClient
|
||||
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(16))
|
||||
d = dht.DHT11(Pin(12))
|
||||
adc = machine.ADC(0)
|
||||
server="10.1.1.162"
|
||||
c = MQTTClient("umqtt_client", server)
|
||||
|
||||
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': 1}
|
||||
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()
|
||||
try:
|
||||
c.connect()
|
||||
c.publish(b"sensors", json.dumps(data))
|
||||
finally:
|
||||
c.disconnect()
|
||||
gc.collect()
|
||||
sleep(2)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
37
uP/mqtt.py
37
uP/mqtt.py
|
@ -1,37 +0,0 @@
|
|||
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)
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue