├── .gitattributes ├── README.md ├── unipager_send_websocket.py └── unipager_send.py /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UniPager-SendWebsocket 2 | ## Version 1: unipager_send_websocket.py 3 | Original from dk4pa 4 | Send local Message over Websocket connection. 5 | 6 | Options are: 7 | 8 | ric, text, m_type(AlphaNum or Numeric), m_func(Func0-3) 9 | 10 | ## Version 2: unipager_send.py 11 | * Password authentification implemented 12 | * Command line arguments with default values 13 | 14 | ```` 15 | usage: unipager_send.py [-h] [--hostname HOSTNAME] [--port PORT] 16 | [--password PASSWORD] [--ric RIC] [--type TYPE] 17 | [--func FUNC] [--msg MSG] [--debug] 18 | 19 | Send paging call direct via Unipager 20 | 21 | optional arguments: 22 | -h, --help show this help message and exit 23 | --hostname HOSTNAME The host running Unipager, default localhost 24 | --port PORT The port Unipager is listening, default 8055 25 | --password PASSWORD The Unipager password, default empty 26 | --ric RIC RIC to send the message to 27 | --type TYPE 0 = Numeric, 1 = Alphanumeric, default 1 28 | --func FUNC Function Bits in POCSAG datagram, default 3 29 | --msg MSG Message, if containing spaces: "TEXT WITH SPACES" 30 | --debug Enable debug 31 | ```` 32 | -------------------------------------------------------------------------------- /unipager_send_websocket.py: -------------------------------------------------------------------------------- 1 | import json 2 | import pprint 3 | import websocket 4 | from websocket import create_connection 5 | websocket.enableTrace(True) 6 | 7 | ws = create_connection('ws://localhost:8055/') 8 | 9 | 10 | ######################################################################## 11 | # Switch Messagetype AlphaNum, Numeric 12 | ######################################################################## 13 | 14 | m_type = "AlphaNum" 15 | #m_type = "Numeric" 16 | 17 | ######################################################################## 18 | # Switch Messagefunction Func0, Func1, Func2, Func3 19 | ######################################################################## 20 | 21 | #m_func = "Func0" 22 | #m_func = "Func1" 23 | #m_func = "Func2" 24 | m_func = "Func3" 25 | 26 | ######################################################################## 27 | # SendMessage with Variables 28 | ######################################################################## 29 | 30 | ric = "1234567" 31 | 32 | text = "TESTNACHRICHT UEBER WEBSOCKET" 33 | 34 | 35 | string_to_send = "{\"SendMessage\": {\"addr\": %s, \"data\": \"%s\", \"mtype\": \"%s\", \"func\": \"%s\"}}" % (ric, text, m_type, m_func) 36 | print(string_to_send) 37 | ws.send(string_to_send) 38 | -------------------------------------------------------------------------------- /unipager_send.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import json 3 | import pprint 4 | import websocket 5 | import argparse 6 | 7 | from websocket import create_connection 8 | 9 | DEBUG = False 10 | 11 | def debug( str ): 12 | if DEBUG: 13 | print str 14 | return 15 | 16 | parser = argparse.ArgumentParser(description='Send paging call direct via Unipager') 17 | parser.add_argument('--hostname', default='localhost', 18 | help='The host running Unipager, default localhost') 19 | parser.add_argument('--port', default='8055', 20 | help='The port Unipager is listening, default 8055') 21 | parser.add_argument('--password', default=None, type=str, 22 | help='The Unipager password, default empty') 23 | parser.add_argument('--ric', dest='ric', default=None, type=int, 24 | help='RIC to send the message to') 25 | parser.add_argument('--type', dest='type', default=1, 26 | help='0 = Numeric, 1 = Alphanumeric, default 1') 27 | parser.add_argument('--func', dest='func', default=3, 28 | help='Function Bits in POCSAG datagram, default 3') 29 | parser.add_argument('--msg', dest='msg', default='', 30 | help='Message, if containing spaces: "TEXT WITH SPACES"') 31 | parser.add_argument('--debug', dest='debug', action='store_true', 32 | help='Enable debug') 33 | 34 | args = parser.parse_args() 35 | DEBUG |= args.debug 36 | if DEBUG: print("Debug enabled") 37 | 38 | hostname = args.hostname 39 | port = args.port 40 | ric = args.ric 41 | type = args.type 42 | func = args.func 43 | msg = args.msg 44 | password = args.password 45 | 46 | if not msg: 47 | print('No message given, nothing to do') 48 | exit() 49 | if not ric: 50 | print('No RIC given, nothing to do') 51 | exit() 52 | 53 | #websocket.enableTrace(True) 54 | 55 | ws = create_connection('ws://' + hostname + ":" + port + '/') 56 | 57 | 58 | ######################################################################## 59 | # Switch Messagetype AlphaNum, Numeric 60 | ######################################################################## 61 | 62 | if type == 0: 63 | m_type = "Numeric" 64 | elif type == 1: 65 | m_type = "AlphaNum" 66 | else: 67 | exit() 68 | 69 | ######################################################################## 70 | # Switch Messagefunction Func0, Func1, Func2, Func3 71 | ######################################################################## 72 | 73 | if func == 0: 74 | m_func = "Func0" 75 | elif func == 1: 76 | m_func = "Func1" 77 | elif func == 2: 78 | m_func = "Func2" 79 | else: 80 | m_func = "Func3" 81 | 82 | ######################################################################## 83 | # SendMessage with Variables 84 | ######################################################################## 85 | 86 | ws.send('{"Authenticate":"' + password + '"}') 87 | string_to_send = "{\"SendMessage\": {\"addr\": %s, \"data\": \"%s\", \"mtype\": \"%s\", \"func\": \"%s\"}}" % (ric, msg, m_type, m_func) 88 | debug(string_to_send) 89 | ws.send(string_to_send) 90 | --------------------------------------------------------------------------------