Page 1 of 1
I want help about arduino uart and raspberry uart
Posted: Tuesday 16 July 2024 14:02
by reza
hi guys
Thank you in advance for your help.
i have an arduino that connected to raspberry(domoticz controller) with uart connection.
on the arduino i have a code that send some data (hex) with uart to raspberry.
I want to receive any data from arduino(with uart) so a dummy device in domoticz goto on or off.
i weak in raspberry and payton. so i need help . thankyou.
Re: I want help about arduino uart and raspberry uart
Posted: Tuesday 16 July 2024 16:13
by waltervl
Install the Mysensors gateway on your arduino, program your sensors/switches and create in Domoticz a MySensors Gateway with USB (serial)
https://www.domoticz.com/wiki/MySensors
Re: I want help about arduino uart and raspberry uart
Posted: Tuesday 16 July 2024 22:42
by reza
thank you for answer.
uart with arduino is just a first example.
some devices have uart connection, no just arduino , i want know how data that send with uart from other devices , in raspberry with pyton and a script connect to domoticz and connect to a dummy device.
i dont want use mysensors and gateway. i want use uart data directly that connect to a dummy device.
Re: I want help about arduino uart and raspberry uart
Posted: Tuesday 16 July 2024 23:15
by waltervl
Then you make a phyton scripts that reads the serial data (loads of examples on the internet) and use Domoticz API calls to send it to Domoticz.
https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s
Here is an example with python that reads data from external and sends it to domoticz
https://www.domoticz.com/wiki/Python_-_ ... o_PVOutput
Here you can find more examples
https://www.domoticz.com/wiki/Scripts#Python_scripts
Re: I want help about arduino uart and raspberry uart
Posted: Thursday 18 July 2024 23:48
by reza
thank you dear waltervl. i see these pages and translate. but i couldn't because i am beginner and I have never worked with Python.
So please guide me with a code snippet.
I will be very thankful.
I did the wiring between my module and the Raspberry Pi board.
vcc = vcc
gnd = gnd
rx = tx
tx = rx
In my module, with the serial port (uart) I send a hex code (00 10) to the Raspberry Pi.
and in raspberry pi i build a dummy device(type= switch and name is TEST) that IDX is 76.
so how when receive hex code (00 10) then my switch(TEST) turn on in domoticz.
can you help me how biuld this script with a example code ?
thank you
Re: I want help about arduino uart and raspberry uart
Posted: Friday 19 July 2024 7:56
by waltervl
If you are a beginner then I would suggest to step into the mysensors project.
Re: I want help about arduino uart and raspberry uart
Posted: Friday 19 July 2024 20:25
by reza
waltervl wrote: ↑Friday 19 July 2024 7:56
If you are a beginner then I would suggest to step into the mysensors project.
i can not use mysensors because i have a board (module) . module's IC is atmega328 and programmed(Not programmed by me and i can not change this program , so i can not use mysensors ) i am know just my module send some data with serial port ( hex data Including 00 10 , 00 20 , 00 30)
i am beginner in python but i worked with arduino and raspberry and i am not beginner in arduino . just about this board i can not access to codes(just hex output)
i am want just connect this hex data to domoticz dummy devices switch.
i seen your help and Auxiliary link but i could not build a code . so i need help for build this code for my problem. can you help me?
even i found this code for rasberry:
Code: Select all
#!/usr/bin/env python3
import serial
if __name__ == '__main__':
ser = serial.Serial('/dev/ttyACM0', 9600, timeout=1)
ser.reset_input_buffer()
while True:
if ser.in_waiting > 0:
line = ser.readline().decode('utf-8').rstrip()
print(line)
that read serial input , but i dont know how read "hex" and how (for example) "if a==00 10(hex)" so send data to a IDX in domoticz...
Re: I want help about arduino uart and raspberry uart
Posted: Friday 19 July 2024 21:52
by waltervl
Sorry, I am also not a programmer.
Perhaps this helps
https://www.tutorialspoint.com/How-to-c ... -in-Python
Re: I want help about arduino uart and raspberry uart
Posted: Friday 19 July 2024 23:55
by reza
Thank you dear
Re: I want help about arduino uart and raspberry uart
Posted: Monday 09 September 2024 22:04
by kimot
There is no easy way to get your format of serial data directly into Domoticz.
If you are not a beginner with Arduino, program a module that will receive serial data from your module and send data via JSON API to Domotic via wifi.
Or use mentioned Mysensor project.
Or learn to write a script that receives data from the serial port and sends it again via api to Domoticz.
It is not an easy task and no one else here will probably do it for you.
I recommend using ChatGPT to create the base of the script.
For example Python:
Code: Select all
import serial
import requests
import json
# Konfigurace sériového portu
SERIAL_PORT = '/dev/ttyUSB0' # Název sériového portu (změň podle potřeby)
BAUD_RATE = 9600 # Rychlost komunikace (změň podle potřeby)
# Konfigurace Domoticz
DOMOTICZ_URL = 'http://domoticz-ip:8080' # URL adresa Domoticz
IDX_DEVICE = 1 # IDX zařízení v Domoticz (změň podle potřeby)
API_KEY = 'Tvoje_API_klic' # API klíč, pokud je potřeba
def send_to_domoticz(value):
"""Funkce pro odeslání hodnoty do Domoticz"""
url = f'{DOMOTICZ_URL}/json.htm?type=command¶m=udevice&idx={IDX_DEVICE}&nvalue=0&svalue={value}'
# Odeslání požadavku na Domoticz
response = requests.get(url)
if response.status_code == 200:
print(f'Úspěšně odesláno do Domoticz: {value}')
else:
print(f'Chyba při odesílání: {response.status_code}')
# Inicializace sériové komunikace
try:
ser = serial.Serial(SERIAL_PORT, BAUD_RATE, timeout=1)
print(f'Sériový port {SERIAL_PORT} otevřen.')
except serial.SerialException as e:
print(f'Chyba při otevírání sériového portu: {e}')
exit()
# Nekonečná smyčka pro čtení dat ze sériového portu
try:
while True:
# Čtení dat ze sériového portu
if ser.in_waiting > 0:
line = ser.readline().decode('utf-8').strip()
print(f'Přijato: {line}')
# Odeslání hodnoty do Domoticz
send_to_domoticz(line)
except KeyboardInterrupt:
print("Ukončuji skript...")
finally:
ser.close()
print(f'Sériový port {SERIAL_PORT} uzavřen.')
Or without Python - only Bash on Raspberry:
Code: Select all
#!/bin/bash
# Konfigurace sériového portu
SERIAL_PORT="/dev/ttyUSB0" # Název sériového portu (změň podle potřeby)
BAUD_RATE="9600" # Rychlost komunikace (změň podle potřeby)
# Konfigurace Domoticz
DOMOTICZ_URL="http://domoticz-ip:8080" # URL adresa Domoticz
IDX_DEVICE=1 # IDX zařízení v Domoticz (změň podle potřeby)
# Čtení ze sériového portu
stty -F $SERIAL_PORT $BAUD_RATE
echo "Otevírám sériový port $SERIAL_PORT s rychlostí $BAUD_RATE..."
# Nekonečná smyčka pro čtení dat ze sériového portu a odesílání na Domoticz
while true; do
# Čtení řádku ze sériového portu
if read -r line < $SERIAL_PORT; then
echo "Přijato: $line"
# Odeslání dat do Domoticz přes API
curl -s --get "$DOMOTICZ_URL/json.htm" \
--data-urlencode "type=command" \
--data-urlencode "param=udevice" \
--data-urlencode "idx=$IDX_DEVICE" \
--data-urlencode "nvalue=0" \
--data-urlencode "svalue=$line"
# Kontrola výsledku
if [ $? -eq 0 ]; then
echo "Data úspěšně odeslána do Domoticz: $line"
else
echo "Chyba při odesílání do Domoticz"
fi
fi
done
Re: I want help about arduino uart and raspberry uart
Posted: Tuesday 10 September 2024 7:28
by gizmocuz
Another option is to look to support MQTT Auto Discovery
Here is an example:
https://github.com/gizmocuz/esp_proximity_sensor_mqtt
Re: I want help about arduino uart and raspberry uart
Posted: Tuesday 10 September 2024 11:52
by FlyingDomotic
Using an ESP8266 instead of an Arduino is probably a (the?) good idea, as ESP has internal WiFi connectivity, allowing you either to send directly API calls to Domoticz, and/or send/receive messages to/from MQTT.
In addition, price would probably be lower.
Advantage is that you could transfer Arduino code you already wrote/got. In addition to Domoticz API, you may also have internal web server, remote debug, syslog traces...
If you're new in programming, you'll have more chances to get ready to use solution on GitHub (or elsewhere), where communication will be embedded for ESP, than for Arduino, which has no native network connectivity.
Don't forget also that a RPi has only 4 USB ports (even if you can add some port extenders), and would have to be located within a meter of all Arduino you'll connect to it. Nice for houses up to 10 m²