I want help about arduino uart and raspberry uart
Moderators: leecollings, remb0
-
- Posts: 112
- Joined: Tuesday 13 September 2016 9:00
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.4
- Contact:
I want help about arduino uart and raspberry uart
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.
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.
- waltervl
- Posts: 5148
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: I want help about arduino uart and raspberry uart
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
https://www.domoticz.com/wiki/MySensors
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- Posts: 112
- Joined: Tuesday 13 September 2016 9:00
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.4
- Contact:
Re: I want help about arduino uart and raspberry uart
thank you for answer.waltervl wrote: ↑Tuesday 16 July 2024 16:13 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
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.
- waltervl
- Posts: 5148
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: I want help about arduino uart and raspberry uart
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
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
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- Posts: 112
- Joined: Tuesday 13 September 2016 9:00
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.4
- Contact:
Re: I want help about arduino uart and raspberry uart
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.waltervl wrote: ↑Tuesday 16 July 2024 23:15 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
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
- waltervl
- Posts: 5148
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: I want help about arduino uart and raspberry uart
If you are a beginner then I would suggest to step into the mysensors project.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- Posts: 112
- Joined: Tuesday 13 September 2016 9:00
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.4
- Contact:
Re: I want help about arduino uart and raspberry uart
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)
- waltervl
- Posts: 5148
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: I want help about arduino uart and raspberry uart
Sorry, I am also not a programmer.
Perhaps this helps https://www.tutorialspoint.com/How-to-c ... -in-Python
Perhaps this helps https://www.tutorialspoint.com/How-to-c ... -in-Python
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- Posts: 112
- Joined: Tuesday 13 September 2016 9:00
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.4
- Contact:
Re: I want help about arduino uart and raspberry uart
Thank you dearwaltervl wrote: ↑Friday 19 July 2024 21:52 Sorry, I am also not a programmer.
Perhaps this helps https://www.tutorialspoint.com/How-to-c ... -in-Python
-
- Posts: 104
- Joined: Saturday 25 November 2017 17:18
- Target OS: Raspberry Pi / ODroid
- Domoticz version: v3.8153
- Location: Czech Rep.
- Contact:
Re: I want help about arduino uart and raspberry uart
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:
Or without Python - only Bash on Raspberry:
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.')
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
RPi2 Domoticz v 4.10717
10 x Sonoff Basic - ESPeasy
1 x Wemos D1 - ESPeasy
1 x Shelly Plus Plug S
1 x Sonoff S26 - ESPeasy
1 x Shelly 1
1 x MySensors HC-SR04
1 x MySenosrs wifi gateway
1 x RFLink
4x Cam IPC-T240H
10 x Sonoff Basic - ESPeasy
1 x Wemos D1 - ESPeasy
1 x Shelly Plus Plug S
1 x Sonoff S26 - ESPeasy
1 x Shelly 1
1 x MySensors HC-SR04
1 x MySenosrs wifi gateway
1 x RFLink
4x Cam IPC-T240H
- gizmocuz
- Posts: 2350
- Joined: Thursday 11 July 2013 18:59
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: Top of the world
- Contact:
Re: I want help about arduino uart and raspberry uart
Another option is to look to support MQTT Auto Discovery
Here is an example:
https://github.com/gizmocuz/esp_proximity_sensor_mqtt
Here is an example:
https://github.com/gizmocuz/esp_proximity_sensor_mqtt
Quality outlives Quantity!
-
- Posts: 303
- Joined: Saturday 27 February 2016 0:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Contact:
Re: I want help about arduino uart and raspberry uart
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²
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²
Who is online
Users browsing this forum: Google [Bot] and 1 guest