Tertiush / ParadoxIP150v2

Python-based IP150 'middle-ware' that uses the IP module's software port for monitoring and control of the alarm via an MQTT Broker.
Eclipse Public License 1.0
73 stars 35 forks source link

MQTT server: can settings handle userid and password? #20

Closed IoTPlay closed 7 years ago

IoTPlay commented 7 years ago

Hi Tertius,

Can this code handle MQTT server setting of userid and password?

I do not see place in the config.ini for such settings?

Tertiush commented 7 years ago

Hi - I've updated the code (IP150-MQTTv2.py file) and config.ini to allow for this. Unfortunately my MQTT broker isn't setup for authentication so I couldn't test it (too much other traffic that will be interrupted). Please give it a go and close this issue if it works for you. thanks

ghost commented 7 years ago

Dankie !

Let m try it.

On 25 September 2017 at 19:01, Tertius notifications@github.com wrote:

Hi - I've updated the code (IP150-MQTTv2.py file) and config.ini to allow for this. Unfortunately my MQTT broker isn't setup for authentication so I couldn't test it (too much other traffic that will be interrupted). Please give it a go and close this issue if it works for you. thanks

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Tertiush/ParadoxIP150v2/issues/20#issuecomment-331945902, or mute the thread https://github.com/notifications/unsubscribe-auth/APgUS0FPUhISha_mK-KdNjmTbrhAUGm_ks5sl9xNgaJpZM4PiYFB .

IoTPlay commented 7 years ago

Hi Tertius, from my test, does not look like it is working yet.

logging to file /var/log/paradoxip.log ERROR:root:*** Error reading config.ini file (will use defaults): No section: 'Application' Traceback (most recent call last): File "./ParadoxIP150v2/IP150-MQTTv2.py", line 913, in reading config logging.error( "MQTT connection error (" + str(attempts) + ": " + e.strerror) AttributeError: 'exceptions.AttributeError' object has no attribute 'strerror'

IoTPlay commented 7 years ago

Although the error says it does not find the [Application] section, it is there:


[IP150] Pincode: 1234 ;Not needed anymore Password: 'xxxxxxxx' IP: 192.168.1.55 IP_Software_Port: 10000

[MQTT Broker] IP: 192.168.1.10 Port: 1883 Mqtt_Username = 'xxxx' Mqtt_Password = 'xxxxxxxxxxx'

[Alarm] Alarm_Model = ParadoxMG5050 ;Currently not used Alarm_Registry_Map = ParadoxMG5050 ;This is used to map to the correct dictionary class within the ParadoxMap.py package. The word "Registers" is appended before loading. Alarm_Event_Map = ParadoxMG5050 ;This is used to map to the correct dictionary class within the ParadoxMap.py package. The word "EventMap" is appended before loading. Zone_Amount = 32

[MQTT Topics] Topic_Publish_Events = Paradox/Events ;The main topic used to publish all events Events_Payload_Numeric = 0 ;1=Events are reported using numeric value [not replaced by the dictionary]. 0=Events are translated to more meaningful text from the dictionary, if your alarm is supported. Topic_Subscribe_Control=Paradox/C/ ;All controls are given through this high-level topic Startup_Publish_All_Info = False ;Upon startup publish all labels from the alarm (configured names of things), only application when reading (updating) labels Topic_Publish_Labels = Paradox/Labels ;The topic used to publish labels Topic_Publish_AppState = Paradox/State ;Publishes the scripts internal states, useful to check if connection is alive Topic_Publish_ZoneState = Paradox/Zone ;Publishes the zone status' with the zone name as the next topic group (1 for open, 0 for closed) Topic_Publish_ArmState = Paradox/Partition ; Publishes the partition status 1 for armed, 0 for disarmed. Publish_Static_Topic = 1 ;Publish events emulated as topics, E.g. Paradox/Events/0/20

[Application] Debug_Mode = 2 ;0=Minimal, 1=Basic, 2=Verbose Startup_Update_All_Labels = False ;Upon startup collect all labels from the alarm (configured names of things). Required for config item: Topic_Publish_Labels. If you see the script stuck at trying to update the labels, then disable this option Log_File = /opt/paradoxip/paradoxip.log Auto_Logoff = True ;When detecting another 3rd party connection to the IP module, logoff for the Logoff_Delay duration (3rd party connection may need to re-attempt their connections Logoff_Delay = 120 ;Delay before reconnection after a 3rd party connection attempt

Tertiush commented 7 years ago

Try to open the file with nano or equivalent and save it (unchanged). This error is usually because of some funny formatting some editor makes. Simply re-saving it with a better editor solves it for me usually. Still haven't figured out the exact cause though...

Tertiush commented 7 years ago

Any update on this? Working or not?

IoTPlay commented 7 years ago

Will try that over the weekend

IoTPlay commented 7 years ago

nope, still the same. Opened config.ini with nano, saved it, closed it. Still same behaviour. I will try next a config.ini without an mqtt uid / pwd, to see if it is caused by that.

IoTPlay commented 7 years ago

Maybe I should also mention (sorry...), I am trying to set your gateway up inside a Docker Image. I will post details of how the Docker image work.

IoTPlay commented 7 years ago

Here is my Docker image (maybe someone has some ideas? I have the config.ini in the same folder as where I fire up the Dockerfile.

I build the Dockerfile on an RPi, where other images are built successfully, from the directory where it, and the config.ini file is with: sudo docker build -f ./python_paradox/Dockerfile_python_paradox.rpi -t iotplay/python_paradox .

IoTPlay commented 7 years ago

The Dockerfile_python_paradox.rpi :

FROM resin/raspberry-pi-alpine-python:latest
RUN apk update && apk upgrade && apk add wget unzip git
RUN mkdir -p /usr/src/iotplay
WORKDIR /usr/src/iotplay
RUN git clone "https://github.com/Tertiush/ParadoxIP150v2.git"
RUN adduser -D iotplay && chown -R iotplay:iotplay /usr/src/iotplay
USER iotplay
COPY ./config.ini /usr/src/iotplay/ParadoxIP150v2
ENV INITSYSTEM on
ENTRYPOINT [ "python", "./ParadoxIP150v2/IP150-MQTTv2.py" ] 
IoTPlay commented 7 years ago

The Python version in the image is 2.7.13, see the Dockerfiile of the image in the first row of my Dockerfile:

https://github.com/resin-io-library/base-images/blob/f67e813bda7886d6cb60f460806b1e33bb4eab4f/python/raspberry-pi/alpine/2.7/Dockerfile

renzorlive commented 7 years ago

I'd made some tests. Actually it's connecting to the MQTT secured server but it seems that is getting SOCKET error.

Logs from IP150.py

2017-10-01 03:27:48,920 INFO Connected to MQTT broker with result code 5  
INFO:root:Connected to MQTT broker with result code 5  
2017-10-01 03:27:49,953 INFO Connected to MQTT broker with result code 5
INFO:root:Connected to MQTT broker with result code 5
2017-10-01 03:27:50,964 INFO Connected to MQTT broker with result code 5
INFO:root:Connected to MQTT broker with result code 5
2017-10-01 03:27:51,976 INFO Connected to MQTT broker with result code 5
INFO:root:Connected to MQTT broker with result code 5
2017-10-01 03:27:52,987 INFO Connected to MQTT broker with result code 5

Logs from MQTT server first with a client, second with IP150 client

1506817591: New connection from 127.0.0.1 on port 1883.
1506817591: New client connected from 127.0.0.1 as MQTT_FX_Client (c1, k60, u'renzor').
1506817591: Sending CONNACK to MQTT_FX_Client (0, 0)

1506817670: New connection from 127.0.0.1 on port 1883.
1506817670: Sending CONNACK to 127.0.0.1 (0, 5)
1506817670: Socket error on client <unknown>, disconnecting.
1506817671: New connection from 127.0.0.1 on port 1883.
1506817671: Sending CONNACK to 127.0.0.1 (0, 5)
1506817671: Socket error on client <unknown>, disconnecting.
1506817672: New connection from 127.0.0.1 on port 1883.
1506817672: Sending CONNACK to 127.0.0.1 (0, 5)
1506817672: Socket error on client <unknown>, disconnecting.

L.E.

Actually it's working, you must type in config.ini the username and password without '' characters.

1506819276: New connection from 127.0.0.1 on port 1883.
1506819276: New client connected from 127.0.0.1 as paho/ADC3D37394C072495D (c1, k60, u'renzor').
1506819276: Sending CONNACK to paho/ADC3D37394C072495D (0, 0)
1506819276: Received SUBSCRIBE from paho/ADC3D37394C072495D
1506819276:     Paradox/C/# (QoS 0)

I think you can close this issue.

IoTPlay commented 7 years ago

Thank you for your effort!! I have also tried it without quotes , was not working, but my password had a ! In the password. Maybe it was that. Let me test with an easy password