metlinkpid-http: HTTP server for Metlink PID
The metlinkpid-http script provides an HTTP endpoint for a Metlink LED passenger information display:
$ metlinkpid-http --serial=/dev/ttyUSB0
Serving on http://127.0.0.1:8080
$ curl 'http://127.0.0.1:8080?12:34+FUNKYTOWN~5|Limited+Express|_Stops+all+stations+except+East+Richard'
{"error":null,"message":"12:34 FUNKYTOWN~5|Limited Express|_Stops all stations except East Richard"}
Installation
pip install metlinkpid-http
Basic usage
Find the device
Determine the device to which the display is connected. On Linux, this can be achieved by disconnecting the display from the computer & reconnecting, then inspecting the contents of dmesg output for USB attachment messages:
[ 3.010816] usb 1-1.4: FTDI USB Serial Device converter now attached to ttyUSB0
The above output indicates that the display is reachable through /dev/ttyUSB0.
Start the HTTP server
Run the script passing that device location as the --serial option:
$ metlinkpid-http --serial=/dev/tty/USB0
The script accepts the following options:
- --serial=PORT
The PID serial device name, such as /dev/ttyUSB0 on Linux or COM1 on Windows. If not specified, defaults to the value of environment variable METLINKPID_SERIAL; if no such variable, defaults to /dev/ttyUSB0.
- --http=HOST:PORT
The hostname/IP address and port to listen on, separated by a colon (:). If not specified, defaults to the value of environment variable METLINKPID_HTTP; if no such variable, defaults to 127.0.0.1:8080.
- -h or --help
Displays usage information similar to above, and provides a link to this documentation.
If the PID successfully connects, the URL is confirmed:
Serving on http://127.0.0.1:8080
Display a message
Next, browse to the specified URL in a browser, adding an appropriately encoded query string to the end:
You should see a plain-text JSON result similar to this:
{"error":null,"message":"MY MESSAGE"}
The same result can be obtained on the terminal using curl:
$ curl 'http://127.0.0.1:8080?MY+MESSAGE'
{"error":null,"message":"MY MESSAGE"}
You could do the same thing in Python like this, using the “requests” library:
>>> import requests
>>> requests.get('http://127.0.0.1:8080?MY+MESSAGE').json()
{'error': None, 'message': 'MY MESSAGE'}
By exposing the display via HTTP in this way, you can operate it using almost any programming language or toolkit.
See the “metlinkpid” module documentation for full details about message formatting.
The HTTP server also periodically pings the display in the background, preventing message display timeout.
Support
Bug reports, feature requests, and questions are welcome via the issue tracker.
- Issue tracker:
Contribute
Pull requests for both code and documentation improvements are gratefully received and considered.
- GitHub repository:
License
This project is licensed under the MIT License.
Metadata
Release files for metlinkpid-http 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| metlinkpid-http-1.0.0.tar.gz | 4.6 kB | Without provenance | Details for metlinkpid-http-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| metlinkpid_http-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for metlinkpid_http-1.0.0-py3-none-any.whl |
Total release size: 9.6 kB
Release files / metlinkpid-http-1.0.0.tar.gz
| Download URL | metlinkpid-http-1.0.0.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
39f8b014a9002765f8abc4a2c9dd35ebe0fbae1406d0146ecc3eb5ddc3f7aa8f
|
|
BLAKE2b-256 checksum How to use checksums |
7264eca15c95b68ec5dec45b89133d82efc9d3609f9266a0887ef344323e520e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3
|
Release files / metlinkpid_http-1.0.0-py3-none-any.whl
| Download URL | metlinkpid_http-1.0.0-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2fca750438a1be5f53ba438076018a4236a5b2f65c55429e2da52f8ecd68a3c9
|
|
BLAKE2b-256 checksum How to use checksums |
5558090b420ee881d86d071ad1dda75d0d4aca71e324818c31aade403dd3f260
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3
|
Security for metlinkpid-http 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.