项目作者: Sparkz0629

项目描述 :
Bluetooth Presence Alerter
高级语言: Shell
项目地址: git://github.com/Sparkz0629/bluetooth_presence_alerter.git
创建时间: 2018-03-29T20:12:50Z
项目社区:https://github.com/Sparkz0629/bluetooth_presence_alerter

开源协议:MIT License

下载


Bluetooth Presence Alerter

A bash based script to ping a list of devices and alert of the presence changes

Getting Started

Prerequisites

The following packages should be installed already, but if they aren’t, then run the following:

  1. sudo apt-get install vim
  2. sudo apt-get install l2ping

Tmux will also be used to run the script in a session that won’t be closed when disconnecting.

  1. sudo apt-get install tmux

Global variables

You will need to set the following global variable

  1. BLUETOOTH_PRESENCE_ALERTER_ROOT

To set this, run the following command:

  1. sudo vim /etc/environment

and add the following

  1. export BLUETOOTH_PRESENCE_ALERTER_ROOT={THE FULL DIRECTORY WHERE YOUR "ping_bluetooth_address.sh" IS LOCATED}

Configuration

The following configuration files are required:

  1. device_list.lst
  2. telegram_bot_properties.props

The contents for device_list.lst should contain the following. Multiple configurations are supported:

  1. DeviceOwner=mac_address
  2. DeviceOwner_2=mac_address_2

The contents for telegram_bot_properties.props should contain the following.

If multiple entries are made, the alert will be sent to each config.

  1. BOT_API_KEY|CHAT_ID
  2. BOT_API_KEY_2|CHAT_ID_2

You may also want to set the bluetooth timeout interval on linux. This will stop the script from running for excessive amounts of time.
Do this as follows:

  1. sudo hciconfig hci0 pageto 8000

Bot Details

Your api key for your bot can be retrieved from bot_father on telegram.

To find your chat_id, do the following (Note: The following should be done without a responsive bot framework hosting your bot).

  1. Create a group with your bot, or a private chat if you are not intending on using the bot in a group.
  2. Send a inline message to the bot (A message starting with “/“)
  3. Run the following command:
    1. curl -i -X GET https://api.telegram.org/bot{BOT_API_KEY}/getUpdates
    You will get a response similar to the following. The chat_id is included in the “chat” section:
    1. {
    2. "ok": true,
    3. "result": {
    4. "message_id": xxx,
    5. "from": {
    6. "id": xxx,
    7. "is_bot": true,
    8. "first_name": "xxx",
    9. "username": "xxx"
    10. },
    11. "chat": {
    12. "id": 12345, //This line contains the CHAT_ID
    13. "title": "xxx",
    14. "type": "xx",
    15. "all_members_are_administrators": true
    16. },
    17. "date": xx,
    18. "text": "xx"
    19. }
    20. }
  4. Use this value in the config file to send messages to this particular group/private chat.

Scheduling

You can start a new tmux session as follows:

  1. tmux new -s1

Then run your script:

  1. ${BLUETOOTH_PRESENCE_ALERTER_ROOT}/ping_bluetooth_address.sh

You can then detach from your session by pressing the following:

  1. "CTRL+b" and then "d"

To re-attach to you sessionso that you can see your script run etc, run the following

  1. tmux attach-session -t1

Remember to detach from your session, and then you can safely close your session.