Getting your drones ip over telegram


#1

I found a cool way to talk to your raspberrypi by creating a telegram bot through their API. or simply go to your telegram account and search for Botfather.
follow the simple instructions and test the example here
after that I modified the example to reply the IP address of the raspberrypi. here is the code below for bot_IP.py

#!/usr/bin/env python

import time
import datetime
import telepot
import subprocess
from telepot.loop import MessageLoop
import socket

s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.connect((“8.8.8.8”,80))
ip = s.getsockname()[0]
s.close

def handle(msg):
chat_id = msg[‘chat’][‘id’]
command = msg[‘text’]
print ‘Got command: %s’ % command

if command == '/ip':
	bot.sendMessage(chat_id, ip)
elif command == '/time':
	bot.sendMessage(chat_id, str(datetime.datetime.now()))

bot = telepot.Bot(‘put your tocken here’)

MessageLoop(bot, handle).run_as_thread()
print ‘working…’

while 1:
time.sleep(10)