Raspberry pi 2 Serial port

Subforum for general discussions. Do not dump your questions/problems here, but try to find the subforum where it belongs!
Post Reply
RKG90
Posts: 4
Joined: Monday 12 February 2018 11:29
Target OS: Raspberry Pi
Domoticz version:
Contact:

Raspberry pi 2 Serial port

Post by RKG90 » Monday 12 February 2018 11:36

Hi

I just installed Domoticz, and is pretty psyched about it :)

I have 4 relays connected to the GPIO. This is working perfectly.

Then i have a "Control panel" from at company called NEETS. This is sending custom serial commands when a button is pressed. Like Power1, Power2 ,etc.

I can read the serial data with minicom on the raspberry

How do i read these serial commands on ttyAMA0 with domoticz and use it to toggle the relays ?

Hope someone can help me out

Best regards

RKG90
Posts: 4
Joined: Monday 12 February 2018 11:29
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Raspberry pi 2 Serial port

Post by RKG90 » Tuesday 13 February 2018 17:52

Is there really No one who can help me ?

User avatar
Marci
Posts: 513
Joined: Friday 22 January 2016 19:00
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Wakefield, West Yorkshire UK
Contact:

Re: Raspberry pi 2 Serial port

Post by Marci » Tuesday 13 February 2018 17:57

Personally, I'd (install &) fire up Node-Red with a node listening to the serial port, listen for the message, reformat the message to comply with Domoticz JSON API, then fire a http request to the relevant Domoticz device via the JSON API.

Quick and easy to get up & running & test / experiment... then once working perfectly it can be refactored out into a script if necessary.
Extended Domoticz homebridge-plugin for latest Homebridge - adds temp/humidity/pressure sensors, power consumption sensors, DarkSkies virtual weather station support, YouLess Meter support, general % usage support & switch/lamp status checking!

RKG90
Posts: 4
Joined: Monday 12 February 2018 11:29
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Raspberry pi 2 Serial port

Post by RKG90 » Tuesday 13 February 2018 18:36

Thanks for the reply..
Is there any examples out there ?

nigels0
Posts: 227
Joined: Thursday 23 January 2014 13:43
Target OS: Raspberry Pi
Domoticz version: 3.8153
Contact:

Re: Raspberry pi 2 Serial port

Post by nigels0 » Tuesday 13 February 2018 22:21

An alternative is to run a looping python script. There are many examples out there. From the script you can make a call to domoticz to switch on using the JSON api.

Here’s a program that I use for reading an alarm serial port and setting a switch in domoticz on/off. You could adapt it to read the text coming from the serial port and decide what to sendto domoticz

Code: Select all

import serial
import os
import urllib2

#Global Variables
ser = 0

#Function to Initialize the Serial Port
def init_serial():
    global ser          #Must be declared in Each Function
    ser = serial.Serial(
        port = '/dev/ttyAMA0',
        baudrate=4800,
        parity= serial.PARITY_EVEN,
        stopbits=serial.STOPBITS_ONE,
        bytesize=serial.EIGHTBITS,
# Need to uncomment this when using hardware DTR 
#       dsrdtr=True,
        timeout=5.0,
        xonxoff=False
    )    

    ser.open()          #Opens SerialPort

#Call the Serial Initilization Function, Main Program Starts from here
init_serial()


active=False
while 1:    
    bytes = ser.readline()  #Read from Serial Port
    print 'You sent: ' + bytes      #Print What is Read from Port

    if len(bytes)>0:
        if active: 
          urllib2.urlopen('http://192.168.0.52:8080/json.htm?type=command&param=switchlight&idx=308&switchcmd=Off')
          active=False
        else:
         urllib2.urlopen('http://192.168.0.52:8080/json.htm?type=command&param=switchlight&idx=308&switchcmd=On')
         active=True
#Ctrl+C to Close Python Window

RKG90
Posts: 4
Joined: Monday 12 February 2018 11:29
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Raspberry pi 2 Serial port

Post by RKG90 » Wednesday 14 February 2018 18:04

Thank you very much

Im getting closer now :)

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests