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
|
from time import sleep
|
||||||
import machine
|
import machine
|
||||||
import dht
|
import dht
|
||||||
from umqtt.simple import MQTTClient
|
from umqtt.robust 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(16))
|
d = dht.DHT11(Pin(12))
|
||||||
adc = machine.ADC(0)
|
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()
|
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': 1}
|
data = {'temp': d.temperature(), 'humid': d.humidity(),'light': adc.read(), 'id': config["id"]}
|
||||||
print(data)
|
print(data)
|
||||||
led(1)
|
led(1)
|
||||||
c.connect()
|
try:
|
||||||
c.publish(b"sensors", json.dumps(data))
|
c.connect()
|
||||||
c.disconnect()
|
c.publish(b"sensors", json.dumps(data))
|
||||||
|
finally:
|
||||||
|
c.disconnect()
|
||||||
gc.collect()
|
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