Compare commits

..

No commits in common. "18b11a95038979a7cb0c7cf0ed946de9d7fac936" and "2eb76abcc515a178952c1792fd7d336a083211f7" have entirely different histories.

3 changed files with 24 additions and 20 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 256 KiB

After

Width:  |  Height:  |  Size: 573 KiB

View File

@ -1,28 +1,15 @@
# Han Mqtt Adapter
### Install
1. Setup picoW with MicroPython [link](https://www.raspberrypi.com/documentation/microcontrollers/micropython.html)
2. Add dependencies (umqtt)
3. Copy main.py and config.py to picoW root
4. Edit config.py to correct SSID, Password and MQTT broker IP
### Protocol
[link to HAN protocol](https://hanporten.se/svenska/protokollet/)
### Hardware
Han port pinout (RJ12):
1. 5V (max 250mA)
Han port pinout:
1. 5V
2. Data request (connect to 5V to enable)
3. Data GND
3. GND
4. NC
5. Data (TX 115200 inverted open drain)
5. DATA (TX 115200 inverted)
6. GND
PicoW connection:
- Connect HAN port pin 1 and 2 to pico 5V
- Connect HAN port pin 3 and 6 to pico GND
- Connect HAN port pin 5 to pico 1 (RX)
- Add pullup resistor (15k) between Pico RX pin and 3V3
Add voltage divider to Pico RX pin:
- 10k between pico RX pin and GND
- 10k between HAN pin 5 and pico RX pin
![front](20220814_231222.MEDIUM.jpeg)
![back](20220814_231229.MEDIUM.jpeg)

17
main.py
View File

@ -45,6 +45,23 @@ wdt.feed()
print("Setting up UART")
uart = machine.UART(0, 115200,invert=UART.INV_RX)
def readUntil(uartObject, termination, maxlen=-1, includeTermination=True):
terminatedFlag=False
result = ''
while maxlen < 0 or len(result) < maxlen:
if uartObject.any():
result += chr(uartObject.read(1)[0])
for terminal in termination:
if result.endswith(terminal):
terminatedFlag=True
if not includeTermination:
result = result[:-len(terminal)]
break
if(terminatedFlag==True):
return result
time.sleep_us(10)
return result
def parse_han_protocol(data):
data = data.replace("'b'", "")
data_list = data.split("\\r\\n")