Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf604c5e30 |
No files matched your search
+1
-2
@@ -1,2 +1 @@
|
||||
data/
|
||||
config.json
|
||||
data/
|
||||
@@ -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.
|
||||
|
||||
## 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
|
||||

|
||||
File renamed without changes.
+9
-20
@@ -2,37 +2,26 @@ from machine import Pin
|
||||
from time import sleep
|
||||
import machine
|
||||
import dht
|
||||
from umqtt.robust import MQTTClient
|
||||
from umqtt.simple 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))
|
||||
d = dht.DHT11(Pin(16))
|
||||
adc = machine.ADC(0)
|
||||
|
||||
c = MQTTClient("umqtt_client", config["mqtt"]["server"],ssl=True, user=config["mqtt"]["user"], password=config["mqtt"]["password"])
|
||||
server="10.1.1.162"
|
||||
c = MQTTClient("umqtt_client", server)
|
||||
gc.enable()
|
||||
|
||||
while True:
|
||||
led(0)
|
||||
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)
|
||||
led(1)
|
||||
try:
|
||||
c.connect()
|
||||
c.publish(b"sensors", json.dumps(data))
|
||||
finally:
|
||||
c.disconnect()
|
||||
c.connect()
|
||||
c.publish(b"sensors", json.dumps(data))
|
||||
c.disconnect()
|
||||
gc.collect()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
sleep(2)
|
||||
|
||||
+37
@@ -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)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user