MohammadReza Sharifi
Published © MIT

Control Raspberry Pi Pico W using Skype Bot

In this project, we use Python to create a bot for the Skype, we can control Raspberry Pi Pico W using this skype bot.

IntermediateWork in progress2 hours109
Control Raspberry Pi Pico W using Skype Bot

Things used in this project

Hardware components

Raspberry Pi Pico W
Raspberry Pi Pico W
×1
Grove - 2-Channel SPDT Relay
Seeed Studio Grove - 2-Channel SPDT Relay
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
LED Light Bulb, Frosted GLS
LED Light Bulb, Frosted GLS
×1

Software apps and online services

VS Code
Microsoft VS Code

Story

Read more

Schematics

circuit diagram in fritzing

Code

print chat id

Python
from skpy import Skype, SkypeChats

user_mname = ""
password = ""

sk = Skype(user_mname, password)  # Connect to Skype
skc = SkypeChats(sk)
chats = skc.recent()  # List recent chats

for chat in chats:
    # Check if 'chat' is an instance of a chat object
    if hasattr(chat, 'id'):
        print(chat.id)  # Print the chat ID
    else:
        print(f"Item is not a chat object: {chat}")

add bot to chat

Python
from skpy import Skype, SkypeChats

user_mname = ""
password = ""

sk = Skype(user_mname, password)  # Connect to Skype
skc = SkypeChats(sk)
chats = skc.recent()  # List recent chats

for chat in chats:
    # Check if 'chat' is an instance of a chat object
    if hasattr(chat, 'id'):
        print(chat.id)  # Print the chat ID
    else:
        print(f"Item is not a chat object: {chat}")

main.py

Python
from skpy import SkypeEventLoop, SkypeNewMessageEvent

user_mname = ""
password = ""

import socket
from time import sleep
# Set up the client socket
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(('192.168.1.234', 80))  # Connect to the server

class SkypeBot(SkypeEventLoop):
    def onEvent(self, event):
        if isinstance(event, SkypeNewMessageEvent):  # Check for new message events
            message_content = event.msg.content  # Get the content of the message
            
            if 'close the door' in message_content.lower():  # Check for a specific keyword
                event.msg.chat.sendMsg('door is close!!!!')  # Send a specific answer
                client_socket.sendall(b'close')
                print("door is close")
                
            elif "open the door" in message_content.lower():
                event.msg.chat.sendMsg("door is open!!!!")
                client_socket.sendall(b"open")
                print("door is open")
                
            elif "turn on the light" in message_content.lower():
                event.msg.chat.sendMsg("light is on!!!")
                client_socket.sendall(b"on")
                print("light is on")
                
            elif "turn off the light" in message_content.lower():
                event.msg.chat.sendMsg("light is off!!!")
                client_socket.sendall(b"off")
                print("light is off")
                
            else:
                pass

bot = SkypeBot(user_mname, password)
bot.loop()

main app on RPi Pico

Python
import socket
import network
from time import sleep
from machine import Pin

ssid = 'Mrsh77'
password = '1m77n2299215r77#'

door_pin = Pin(14,Pin.OUT)
light_pin = Pin(15,Pin.OUT)

door_pin.value(0)
light_pin.value(0)

def connect():
    #Connect to WLAN
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    wlan.connect(ssid, password)
    while wlan.isconnected() == False:
        print('Waiting for connection...')
        sleep(1)
    ip = wlan.ifconfig()[0]
    print(f'Connected on {ip}')
    return ip

def open_socket(ip):
    address = (ip,80)
    connection = socket.socket()
    connection.bind(address)
    connection.listen(1)
    #print(connection)
    return connection


try:
    ip = connect()
    connection = open_socket(ip)
    while True:
        # Accept a connection from a client
        client, addr = connection.accept()
        print(f'Connected to {addr}')
        while True:
            # Receive data from the client
            data = client.recv(1024)
            if data:
                # Print the data to the console
                print(data)
                
                if data == b"on":
                    light_pin.value(1)
                    print("light is on")
                    
                elif data == b"off":
                    light_pin.value(0)
                    print("light is off")
                    
                elif data == b"open":
                    door_pin.value(1)
                    print("door is open")
                    
                elif data == b"close":
                    door_pin.value(0)
                    print("door is close")
                    
                else:
                    pass
                
except KeyboardInterrupt:
    # Close the server socket
    connection.close()

Credits

MohammadReza Sharifi
13 projects • 8 followers
I'm an Electrical Engineer and Maker.
Contact

Comments

Please log in or sign up to comment.