pajikos / sms-gammu-gateway

Simple SMS REST API gateway for sending SMS from gammu supported devices
Apache License 2.0
116 stars 31 forks source link

Integration with HA access error #1

Closed jjanderson closed 4 years ago

jjanderson commented 4 years ago

Hello,

I have followed the steps and can successfully send an sms on the RPI CLI with command:

sudo gammu sendsms TEXT 0779REDACTED -text "Ohhai"

However, in home assistant, when I try and use /developer-tools/service with data:

{ "message": "Hello, how are you?", "target": "+4REDACTED" }

Failed to call service notify/sms_gw. HTTPConnectionPool(host='RED.ACT.ED.!', port=5000): Max retries exceeded with url: /sms (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f7acfb41890>: Failed to establish a new connection: [Errno 111] Connection refused'))

I have changed the username and password in the credentials.txt.file, however these are reflected in my notification component which looks like this:

  • name: SMS GW platform: rest resource: http://RED.ACT.ED.!:5000/sms method: POST_JSON authentication: basic username: !secret gammuusername password: !secret gammuuserpass target_param_name: number message_param_name: text

WOuld you mind helping me to try and get this working?

pajikos commented 4 years ago

Hi, it seems that your HA instance cannot connect to your endpoint. Try to call your service outside of HA, e.g. using CURL (from CLI), Postman (Chrome extension) or whatever you prefer.

Parameters are really simple:

Method: POST 
URL: http://xxx.xxx.xxx.xxx:5000/sms
Content-Type: application/json
Authorization: Basic gammuusername gammuuserpass
Body:
{
  "text": "Hello, how are you?",
  "number": "+420xxxxxxxxx"
}
jjanderson commented 4 years ago

Hi, so I changed my credentials.txt file with sudo nano credentials.txt. and saved accordingly (ctrlx, y, return)

When I run python3 run.py

I get

pi@rpi31:~/sms-gammu-gateway $ dir
credentials.txt  Dockerfile  gammu.config  LICENSE  __pycache__  README.md  requirements.txt  run.py  support.py
pi@rpi31:~/sms-gammu-gateway $ python3 run.py
Traceback (most recent call last):
  File "run.py", line 11, in <module>
    user_data = load_user_data()
  File "/home/pi/sms-gammu-gateway/support.py", line 8, in load_user_data
    with open(filename) as credentials:
FileNotFoundError: [Errno 2] No such file or directory: '/credentials.txt'

I appreciate that this may be down to gammu on RPI. so possibly I should raise the issue there? I just thought I would ask here first.... let me rebuild again and then take it from there.... if you have any insight on the above error, that would be great. Thanks

jjanderson commented 4 years ago

So purged everything and reinstalled with the following blow by blow... on the standalone install, it would appear that there is an issue with either the intructions or the credentials.txt file (Which as you can see from the steps below remainde untouched this time)

root@rpi31:/home/pi# apt-get update && apt-get install -y pkg-config gammu libgammu-dev libffi-dev
Get:1 http://archive.raspberrypi.org/debian stretch InRelease [25.4 kB]
Hit:2 http://raspbian.raspberrypi.org/raspbian stretch InRelease
Fetched 25.4 kB in 0s (28.9 kB/s)
Reading package lists... Done
Reading package lists... Done
Building dependency tree
Reading state information... Done
libffi-dev is already the newest version (3.2.1-6).
libgammu-dev is already the newest version (1.38.1-1).
pkg-config is already the newest version (0.29-4).
The following additional packages will be installed:
  libgudev-1.0-0
Suggested packages:
  wammu gammu-doc
The following NEW packages will be installed:
  gammu libgudev-1.0-0
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/284 kB of archives.
After this operation, 625 kB of additional disk space will be used.
Selecting previously unselected package libgudev-1.0-0:armhf.
(Reading database ... 38740 files and directories currently installed.)
Preparing to unpack .../libgudev-1.0-0_230-3_armhf.deb ...
Unpacking libgudev-1.0-0:armhf (230-3) ...
Selecting previously unselected package gammu.
Preparing to unpack .../gammu_1.38.1-1_armhf.deb ...
Unpacking gammu (1.38.1-1) ...
Processing triggers for libc-bin (2.24-11+deb9u4) ...
Processing triggers for man-db (2.7.6.1-2) ...
Setting up libgudev-1.0-0:armhf (230-3) ...
Setting up gammu (1.38.1-1) ...
Processing triggers for libc-bin (2.24-11+deb9u4) ...
root@rpi31:/home/pi# git clone https://github.com/pajikos/sms-gammu-gateway
fatal: destination path 'sms-gammu-gateway' already exists and is not an empty directory.
root@rpi31:/home/pi# cd sms-gammu-gateway
root@rpi31:/home/pi/sms-gammu-gateway# pip3 install -r requirements.txt
Requirement already satisfied: python-gammu in /usr/local/lib/python3.5/dist-packages (from -r requirements.txt (line 1))
Requirement already satisfied: flask in /usr/local/lib/python3.5/dist-packages (from -r requirements.txt (line 2))
Requirement already satisfied: flask-restful in /usr/local/lib/python3.5/dist-packages (from -r requirements.txt (line 3))
Requirement already satisfied: Flask-HTTPAuth in /usr/local/lib/python3.5/dist-packages (from -r requirements.txt (line 4))
Requirement already satisfied: pyopenssl in /usr/local/lib/python3.5/dist-packages (from -r requirements.txt (line 5))
Requirement already satisfied: itsdangerous>=0.24 in /usr/local/lib/python3.5/dist-packages (from flask->-r requirements.txt (line 2))
Requirement already satisfied: Jinja2>=2.10.1 in /usr/local/lib/python3.5/dist-packages (from flask->-r requirements.txt (line 2))
Requirement already satisfied: Werkzeug>=0.15 in /usr/local/lib/python3.5/dist-packages (from flask->-r requirements.txt (line 2))
Requirement already satisfied: click>=5.1 in /usr/local/lib/python3.5/dist-packages (from flask->-r requirements.txt (line 2))
Requirement already satisfied: six>=1.3.0 in /usr/lib/python3/dist-packages (from flask-restful->-r requirements.txt (line 3))
Requirement already satisfied: pytz in /usr/local/lib/python3.5/dist-packages (from flask-restful->-r requirements.txt (line 3))
Requirement already satisfied: aniso8601>=0.82 in /usr/local/lib/python3.5/dist-packages (from flask-restful->-r requirements.txt (line 3))
Requirement already satisfied: cryptography>=2.3 in /usr/local/lib/python3.5/dist-packages (from pyopenssl->-r requirements.txt (line 5))
Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python3.5/dist-packages (from Jinja2>=2.10.1->flask->-r requirements.txt (line 2))
Requirement already satisfied: cffi!=1.11.3,>=1.8 in /usr/local/lib/python3.5/dist-packages (from cryptography>=2.3->pyopenssl->-r requirements.txt (line 5))
Requirement already satisfied: asn1crypto>=0.21.0 in /usr/local/lib/python3.5/dist-packages (from cryptography>=2.3->pyopenssl->-r requirements.txt (line 5))
Requirement already satisfied: pycparser in /usr/local/lib/python3.5/dist-packages (from cffi!=1.11.3,>=1.8->cryptography>=2.3->pyopenssl->-r requirements.txt (line 5))
root@rpi31:/home/pi/sms-gammu-gateway# nano gammu.config
root@rpi31:/home/pi/sms-gammu-gateway# python3 run.py
Traceback (most recent call last):
  File "run.py", line 11, in <module>
    user_data = load_user_data()
  File "/home/pi/sms-gammu-gateway/support.py", line 8, in load_user_data
    with open(filename) as credentials:
FileNotFoundError: [Errno 2] No such file or directory: '/credentials.txt'
pajikos commented 4 years ago

I made it primary for docker, please check out this project again, I have fixed some absolute paths in support.py. I hope it helps.

jjanderson commented 4 years ago

spun up in docker and workig fine.... thanks!