We’ll need to enable a virtual environment. Make sure you have venv installed:
sudo apt install python3.11-venv
Navigate to project directory and creante a virtual enviromnent:
source .venv/bin/activate
Install libraries for influxdb and DS18B20 sensor:
pip install influxdb-client w1thermsensor
In my case I want a python script that runs every X minutes and sends the reading to influxdb.
Below is an example:
from w1thermsensor import W1ThermSensor
from w1thermsensor.errors import NoSensorFoundError
from influxdb_client import InfluxDBClient, Point, WritePrecision
from influxdb_client.client.write_api import WriteOptions
import time
INFLUXDB_URL ="replaceme"INFLUXDB_TOKEN ="replaceme"INFLUXDB_ORG ="Home"INFLUXDB_BUCKET ="weather"client = InfluxDBClient(url=INFLUXDB_URL, token=INFLUXDB_TOKEN, org=INFLUXDB_ORG)
write_api = client.write_api(write_options=WriteOptions(batch_size=1))
# Initialize the DS18B20 sensortry:
sensor = W1ThermSensor()
except NoSensorFoundError as e:
print("Sensor not connected")
exit(1)
# Read temperature from the sensortemperature = sensor.get_temperature()
# Prepare the data pointpoint = Point("temperature") \
.tag("location", "exterior-1") \
.field("temperature", temperature) \
.time(time.time_ns(), WritePrecision.NS)
write_api.write(INFLUXDB_BUCKET, INFLUXDB_ORG, point)
print(f"Temperature data sent to InfluxDB: {temperature:.2f}°C")
client.close()
Next let’s configure this script to run every 15 mins using crontab:
I always wanted to build a game from scratch using an Arduino and combine this with my woodworking skills.
When Agata was 1 year old, I used this as a pretext (so she can play) and built a wooden box where I could mount 4 buttons, added an LCD and there you go, the foundations for any game with 4 coloured buttons and a display.
My project was a reaction game. Press a button to start the game, then a random coloured button will light up and you need to press it in a given time.
On the LCD there’s a progress bar showing how much time you have. The game starts with a time limit of 2.5 seconds to press the button, then with each press, time decreases with 50 ms until it reaches 750ms / interval and then keep it at 750ms as anything below that is too fast to react to. My top score is 48 presses :-)
I’m mostly working with PHP and for this I’m using PhpStorm - best IDE for php development, at least when using a framework like Laravel.
When inspecting code, if you’re like me and see something fishy, first thing I do is to check annotations (right click on the line numbers and click “Annotate”), so I can see how worked on that part of the code - this is also a shortcut to see git history, since if you click on the annotation, it will show you the git history.
I had a couple of ESP32 laying around and I’ve been waiting for an excuse to put them to work. I’m working from home and one of the issues I had was to let my wife and child know that I’m in a conference, so I don’t want to be disturbed.
I found out about ESP-NOW, the protocol developed by Espressif, and I immediately thought about making a notification system that will show a red light when I press a button. We’re talking about 2 devices, one sits at my desk - the button, and another one sits in the living room - the red light. When I’m in a conference, I press the button, which will turn on the red light.