This bot use a submodule with motion repository
This code has been tested with motion in:
- Fedora distro
- Raspberry pi TODO
TODO requirements.txt
This bot and server use motion source code. You can find it in the original github project page or use it as submodule.
- Get the code (Currently use v4.0)
git submodule init
git submodule update
- Compile the code
autoreconf -fiv
./configure
make
make install
This bot use a token to be used by telegram api. Make http requests to server if is running.
This code shall be used to create a bot using a valid id from fatherbot. vgonisanz use it to create its own motion-api-bot to be used by anyone. You can get another id and create a similar bot with your own changes.
- client: Main script to manage bot. Contain usage and use api file to make all calls to the server.
- api: Client to manage telegram python api and make calls to core. Is used by bot script. Use HTTP request to get info from a running server.
This code is used to have a server with motion installed to start and stop getting data and other operations.
- server: Main script to manage server based on linkero.
- core: Client api of linkero to feed bot http requests.
All services can be requested using /api/v1
.
Bot is an instance running in bot computer. It can be host by anyone. You will need to register your server in order to use it thought telegram.
cd bot
python client.py
Server is an instance running in host computer to manage motion library and using its webcam as defined into configuration file.
Launch server with command:
cd server
python server.py
Output logs from server example:
INFO:werkzeug: * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
INFO:werkzeug:127.0.0.1 - - [01/Oct/2017 13:38:42] "GET /cmds HTTP/1.1" 200 -
- First line: Where is the server running
- Second line: A GET HTTP request was caught to cmds URL.
Exist several ways to use the server.
- Curl: This executable (it can be used as library too) have a lot of options to make HTTP requests.
- Python client script: Running client.py sample script, parse args to make requests.
- Just running:
curl -i -X GET http://localhost:5000/v1/help
- More info:
curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://localhost:5000/todos/todo1
- Just running:
curl -i -X POST http://localhost:5000/todos/todo1
Put is used to:
curl -X PUT -d arg=val -d arg2=val2 localhost:8080
Delete is used to:
curl -i -X DELETE http://localhost:3001/api/v1/projects/559a328d8e67197a1c00d6dd
curl --data "param1=value1¶m2=value2" http://hostname/resource
curl --form "[email protected]" http://hostname/resource
- -X: Specifies a custom request method to use when communicating with the HTTP server. Valid: GET, POST, PUT, DELETE
- -H: Extra header to include in the request when sending HTTP to a server.
- -i: Include the HTTP-header in the output.