Have you ever said, "I wish I had a personal assistant"? Yeah, everyone needs a personal assistant to do things. Now here I am introducing a personal assistant based on Linklt Smart 7688 Duo and Telegram. It has both the powers of Linux and Arduino.
JARVISYeah, it's a personal assistant based on Linklt Smart 7688 Duo and Telegram Bot. We can directly chat to our Jarvis Bot for getting information like temperature and humidity in your house or to read the latest news from BBC or whatever your preference. You can also control home appliances via chatting with your bot.
Network Connectivity
When building this solution, we're assuming connectivity to the internet is available. This can be through a home WiFi network, or a cellular phone can be used to tether the devices to the internet. So we need to setup the WiFi first.
Power Supply
For Linklt, we only need 5v, so we can use a power bank. The relay connection needs 240v AC, so we can only control 240V AC via 5v relay.
Let's make it!
Step 1 - Create a Telegram Bot1.1 Open the Telegram app on your system or mobile.
Download the app from here: Telegram.
1.2 Search for "BotFather".
1.3 Open "BotFather".
1.4 Start "BotFather".
1.5 Create a new Bot.
Bot: Salmanfaris_bot
1.6 Obtain access token
2.1 Connect to Linklt 7688 Duo
🠚 After connecting to its WiFi, open the web browser and go to http://mylinkit.local./ to access Linklt:
2.2 Connect to the Internet
🠚 After entering the Linklt control panel, change it to Station Mode
3.1 Install Arduino IDE
🠚 Install the latest Arduino IDE here
3.2 Install Linklt 7688 Duo Board Definition
Open:
- File 🠚 Preferences
http://download.labs.mediatek.com/package_mtk_linkit_smart_7688_index.json
Copy and paste code there.
🠚 After that open
- Tools 🠚 Boards 🠚 Boards Manager
🠚 Open the Boards Manger and search for Linklt 7688 Duo
🠚 Install the Board definition
🠚 Connect Linklt to Arduino
🠚 Select Port and Board in the tools Section
🠚 Upload the code
//salman faris
// code for linklt Smart 7688 Duo Jarvis project
#include <DHT.h>
#define DHTPIN A1 // what pin we're connected to
#define DHTTYPE DHT11 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino
int chk;
float hum; //Stores humidity value
float temp; //Stores temperature value
void setup() {
dht.begin(); //begin the DHTT
Serial.begin(115200); // open serial connection to USB Serial
//port(connected to your computer)
Serial1.begin(57600); // open internal serial connection to
//MT7688
pinMode(13, OUTPUT); // Bedroom light
pinMode(12,OUTPUT); // kitchen light
}
void loop() {
hum = dht.readHumidity(); // readhumdity
temp= dht.readTemperature(); //read temperature
int c = Serial1.read(); // read from MT7688
if (c != -1) {
switch(c) {
case '0': // turn off D13 when receiving "0"
digitalWrite(13, 0);
break;
case '1': // turn on D13 when receiving "1"
digitalWrite(13, 1);
break;
case '2':
digitalWrite(12,0);
break;
case '3':
digitalWrite(12,1);
break;
case '4':
Serial1.print(hum);
break;
case '5':
Serial1.print(temp);
break;
}
}
}
Step 5: WiringDHT11
- Data pin 🠚 A0
- VCC 🠚 5v
- GND 🠚 Ground
Relay
- IN1 🠚 D13 pin
- IN2 🠚 D12 pin
- VCC 🠚 5v
- GND 🠚 Ground
Here I used a Mi Band 2 case.
Step 7: Connecting RelayConnect Linklt to the internet. Install PuTTY and WinSCP.
8.1 : Open PuTTY
8.2 Connect Pi via SSH
8.3 Install "telepot"
pip install telepot
8.4 Python code
Create a folder with the name Telegram and create a Python file there. Name it bot.py using Vim editor.
vi bot.py
Copy paste the code:
#coder :- Salman Faris
import sys
import mraa
import time
import random
import datetime
import telepot
import serial
s= None
def setup():
global s
s = serial.Serial("/dev/ttyS0", 57600)
def handle(msg):
chat_id = msg['chat']['id']
command = msg['text']
print 'Got command: %s' % command
if command =='/start':
bot.sendMessage(chat_id,"Hi, Am Jarvis Your Personal Assistant Powerd by Linit7688 Duo developed by Salman Faris. ")
bot.sendMessage(chat_id,"Am here to help You...! ")
bot.sendMessage(chat_id,"to know more about my command type /help")
elif command == '/help':
bot.sendMessage(chat_id,"/TurnOnBedroomLight or /TurnOffBedroomLight :- to turn on/off bedroom light")
bot.sendMessage(chat_id,"/TurnOnKitchenLight or /TurnOffKitchenLight :- to turn on/off Kitchen light")
bot.sendMessage(chat_id,"/TurnOnLights or /TurnOffLights :- to turn on/off all the light")
bot.sendMessage(chat_id,"/RoomTemp :- To know about Room Temperature ")
bot.sendMessage(chat_id,"/RoomHumi :- To know about Room Humidity ")
bot.sendMessage(chat_id,"/News :- To read Latest News ")
s.write("1")
elif command == '/TurnOnBedroomLight':
bot.sendMessage(chat_id,"ok..Bedroom light now ON")
s.write("1")
elif command =='/TurnOffBedroomLight':
bot.sendMessage(chat_id,"ok...Bedroom light now OFF")
s.write("0")
elif command == '/TurnOnKitchenLight':
bot.sendMessage(chat_id,"ok...kitchen light now ON")
s.write("3")
elif command == '/TurnOffKitchenLight':
bot.sendMessage(chat_id,"ok...kitchen light now OFF")
s.write("2")
elif command == '/TurnOnLights':
bot.sendMessage(chat_id,"bedroom and kitchen light's are On")
s.write("1")
s.write("3")
elif command == '/TurnOffLights':
bot.sendMessage(chat_id,"bedroom and kitchen light's are On")
s.write("0")
s.write("2")
elif command == '/RoomTemp':
bot.sendMessage(chat_id,"Temperature is")
s.write("5")
a = s.read(5)
bot.sendMessage(chat_id,a)
bot.sendMessage(chat_id,"Celsius")
elif command == '/RoomHumi':
bot.sendMessage(chat_id,"Humidity is ")
s.write("4")
a = s.read(5)
bot.sendMessage(chat_id,a)
elif command == '/News':
bot.sendMessage(chat_id,"http://www.bbc.com/news/world")
bot.sendMessage(chat_id,"http://timesofindia.indiatimes.com/news")
bot.sendMessage(chat_id,"http://www.ndtv.com/latest")
else:
bot.sendMessage(chat_id,"Wrong Command")
bot.sendMessage(chat_id,"please check /help section to know more about Command's")
bot = telepot.Bot('your bot token')
bot.message_loop(handle)
print 'I am listening...'
while True:
setup()
Or clone the git:
https://github.com/salmanfarisvp/Jarvis-Linklt7688.git
Add your Bot Token here:
bot = telepot.Bot('bot Token here')
Step 9: Run the Python Codepython bot.py
Now the code part is completed.
Step 10: Test the Telegram Bot🠚 Thank You. Enjoy my Bot.
Comments