FEAT : Nouveau relais

This commit is contained in:
Raymond Bourges 2026-01-19 12:28:45 +01:00
parent 109424fc50
commit e719b6058c
2 changed files with 48 additions and 30 deletions

14
borne.code-workspace Normal file
View File

@ -0,0 +1,14 @@
{
"folders": [
{
"path": "."
},
{
"name": "Mpy Remote Workspace",
"uri": "pico:"
}
],
"settings": {
"python.languageServer": "Pylance"
}
}

22
main.py
View File

@ -1,9 +1,10 @@
from machine import Pin, I2C from machine import Pin
from neopixel import NeoPixel from neopixel import NeoPixel
import network import network
import time import time
import urequests import urequests
import sys
Broche = [0, 1, 2, 21, 22, 23, 16, 17, 19, 20, 18] Broche = [0, 1, 2, 21, 22, 23, 16, 17, 19, 20, 18]
@ -52,20 +53,16 @@ class Bouton:
self.todo() self.todo()
class Relais: class Relais:
i2c = I2C(scl=Pin(Broche[5]), sda=Pin(Broche[4]), freq=20000) pin = Pin(Broche[5], Pin.OUT) #
I2C_ADDR = 0x11
def __init__(self) -> None: def __init__(self) -> None:
self.solaire() self.solaire()
def off(self):
self.i2c.writeto_mem(self.I2C_ADDR, 0x10, bytes([0b0000]))
def solaire(self): def solaire(self):
self.i2c.writeto_mem(self.I2C_ADDR, 0x10, bytes([0b0011])) self.pin.off()
def reseau(self): def reseau(self):
self.i2c.writeto_mem(self.I2C_ADDR, 0x10, bytes([0b1100])) self.pin.on()
class Cloud: class Cloud:
token_ha = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJkNGY4MDdmYWYzNDQ0NTc0ODY4MmFmNzA4NDdmMTE0MyIsImlhdCI6MTc2NDQ1Mzk0NSwiZXhwIjoyMDc5ODEzOTQ1fQ.DJgSqeTKPHWbKEFH3HuFih4QKt3CSqLqot34_vhCOQU" token_ha = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJkNGY4MDdmYWYzNDQ0NTc0ODY4MmFmNzA4NDdmMTE0MyIsImlhdCI6MTc2NDQ1Mzk0NSwiZXhwIjoyMDc5ODEzOTQ1fQ.DJgSqeTKPHWbKEFH3HuFih4QKt3CSqLqot34_vhCOQU"
@ -210,6 +207,8 @@ consigne = 80
solaire = True solaire = True
while True: while True:
time.sleep(pas_temps)
try:
solaire = True solaire = True
i = (i + 1) % 10 i = (i + 1) % 10
print(f"-------------- {i}") print(f"-------------- {i}")
@ -232,4 +231,9 @@ while True:
else: else:
print(f"On force le réseau : consigne ({consigne}) ; charge ({charge}) ; HC/HP ({"HC" if HC else "HP"})") print(f"On force le réseau : consigne ({consigne}) ; charge ({charge}) ; HC/HP ({"HC" if HC else "HP"})")
relais.reseau() relais.reseau()
time.sleep(pas_temps) except Exception as e:
print("!!! ERREUR !!!")
sys.print_exception(e)
# print(type(e))
# print(e.args)
# print(e)