Send Sensor Data to Database

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
JimFranklin
Posts: 1
Joined: Thu Oct 31, 2019 2:03 am

Send Sensor Data to Database

Post by JimFranklin » Thu Oct 31, 2019 2:20 am

I have a WeMo D1 Mini 8266 board and I have successfully done the following so far:

1 Using uPyCraft IDE I have installed the MicroPython Firmware: esp8266-20190529-v1.11.bin
2 Added code to set and update the clock (RTC) via ntptime
3 Added code to connect reliably to wifi

I see how to capture data from a sensor, but have not implemented that yet. That looks easy.

But I am now trying to prepare for sending that sensor data (or any data) to a database, and I do not see how to make that happen.
I have a PostgreSQL database ready and waiting - I can connect to it from the pgAdmin tool and insert data. I don't want to send the data to a cloud service, and don't want to make another process ping this board to retrieve the sensor data. I want the board to take a reading and send it to the db.
I have inserted into databases outside of the MicroPython world via java, javascript, etc... so I am comfortable with that.
I see there is a port of the psycopg2 driver called micropg here:
https://github.com/nakagami/micropg
and it shows how to install it - either using the upip tool or copying the micropg.py file.
It is here that I am having trouble. If I am within the uPyCraft IDE and have the board connected I can do:
import micropython
import upip
but when I then run:
micropython -m upip install micropg
it says:
Traceback (most recent call last):
File "<stdin>", line 1
SyntaxError: invalid syntax

So then I tried loading the setup.py and micropg.py files to the board and running them but get similar errors.

I'm not sure where to try to install the micropg driver, and could use some direction.

Thanks.

User avatar
ghayne
Posts: 42
Joined: Sat Jun 08, 2019 9:31 am
Location: Cwmllynfell, Wales

Re: Send Sensor Data to Database

Post by ghayne » Thu Oct 31, 2019 10:04 am

Try urequests to post data via http to the database.

Post Reply