summaryrefslogtreecommitdiff
path: root/Readme.md
blob: 0c0f5c79067b69e3c1e268bbb183da02792cfe63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Micropython project for Raspberry Pi Pico.
Collects data from a onewire temperature sensor
and feeds it to MQTT on a wireless connection.

Before you can use it you need to:
- connect onewire sensor to Pico,
- set up MQTT broker on a server,
- optionally, but highly advisable, setup ntpd server in local network,
- set up certificates (check out the MQTT_for_pie repo),
- provide settings in config.py. Skeleton in config.py.example

Notes:

In order to test Pico, best use Thonny.
At the time of writing this (Jun 2024), you won't be able to see live
interpreter in PyCharm
You will need kernel config options enabled:
    (Most likely:)
    CONFIG_USB_SERIAL_GENERIC
    CONFIG_USB_SERIAL_SIMPLE
    (Definitely:)
    CONFIG_USB_ACM

Device path should be /dev/ttyACM0

To connect to it, add your user to dialout group.
Alternatively change permissions on that device to something like:
chmod o+rw /dev/ttyACM0
Or change owner on that device to your user

To address pin 25 with LED use "LED":
from machine import Pin
led = Pin("LED", Pin.OUT)

Before using tls (mosquitto, requests) you'll need to set time, for instance:
import ntptime
ntptime.settime()
Be aware that default timeout on a socket is 1 second, which may not be enough.
I'm using usocket directly so that I can set timeout to a larger value.
The hard part is to deal with timeout from ntp server.
I managed to cut down timeouts drastically by running my own ntp server on local network.

Another hard part is setting up certificates so that umqttsimple can use them.
TLDR, do it like that: https://github.com/JustinS-B/Mosquitto_CA_and_Certs/blob/main/client_maker

Update:
Script from that link, now dead, provided here as client_maker.sh

For background information: https://github.com/orgs/micropython/discussions/10559

Script for server running MQTT reading data from MQTT and updating rrd database
in separate project, with Bash script generating rrd database and
generating graph from this database.

Controlling temperature with PID not tested.