Git Product home page Git Product logo

Comments (4)

vshymanskyy avatar vshymanskyy commented on July 16, 2024

Which hardware/os do you have? Please also provide your script code.

from blynk-library-python.

iker190 avatar iker190 commented on July 16, 2024

Hi, I'm using a raspberry pi 3 running Raspbian 9 stretch and Python 3.5.3.
Here is my code:

import serial
import yaml
import BlynkLib
from time import sleep

MENU = [[1], [2, 3], [4], [5], [2], [3], [1, 2, 3, 4, 5]]
BLYNK_AUTH = 'my token'
serial = serial.Serial("/dev/ttyACM0", 9600, timeout=1)
blynk = BlynkLib.Blynk(BLYNK_AUTH)

def read_config_file(conf=2):
    with open("config.yaml", "r") as codes_file:
        config = yaml.load(codes_file)
        if conf == 2:
            return config
        if conf == 1:
            return config["configuration"]
        if conf == 0:
            return config["persianas"]
        
def send_command(cmd):
    if not lock:
        for blind in current_blind:
            command = blind_config[blind-1][cmd]
            print(command)
            serial.write(command.encode())
            sleep(0.1)
            serial.write(command.encode())
            sleep(0.5)
        
@blynk.VIRTUAL_WRITE(0)
def lock_handler(status):
    global lock 
    lock = int(status[0])
        
@blynk.VIRTUAL_WRITE(1)
def blind_handler1(sel):
    blind_read_handler1()
    sel = int(sel[0])
    global current_blind
    current_blind = []
    for i in range(len(MENU[sel-1])):
        current_blind.append(MENU[sel-1][i])

@blynk.VIRTUAL_WRITE(3)
def blind_handler2(sel):
    blind_read_handler2()
    sel = int(sel[0])+4
    global current_blind
    current_blind = []
    for i in range(len(MENU[sel-1])):
        current_blind.append(MENU[sel-1][i])
        
@blynk.VIRTUAL_READ(3)
def blind_read_handler2():
    blynk.virtual_write(1, 0)
    
@blynk.VIRTUAL_READ(1)
def blind_read_handler1():
    blynk.virtual_write(3, 0)
                
@blynk.VIRTUAL_WRITE(2)
def command_handler(cmd):
    cmd = int(cmd[0])
    if cmd == 1:
        send_command("up")
    if cmd == 2:
        send_command("down")
    if cmd == 3:
        send_command("stop")
    
full_config = read_config_file()
blind_config = full_config["persianas"]
setting_config = full_config["configuration"]
current_blind = []
lock = 1

while True:
    blynk.run()

from blynk-library-python.

iker190 avatar iker190 commented on July 16, 2024

It's been working now for a week without any error. The program remains unchanged.

from blynk-library-python.

jraiwi avatar jraiwi commented on July 16, 2024

I am facing the same issue and not solved.
I am using NodeMCU ESP8266 and micropython.
I get the error Unexpected command: 41 when using blynk:
Below is my code ....

import BlynkLib
import network
import machine

WIFI_SSID = 'HamzaJraiwi'
WIFI_PASS = ''

BLYNK_AUTH = ''

print("Connecting to WiFi...")
wifi = network.WLAN(network.STA_IF)
wifi.active(True)
wifi.connect(WIFI_SSID, WIFI_PASS)
while not wifi.isconnected():
pass

print('IP:', wifi.ifconfig()[0])

print("Connecting to Blynk...")
blynk = BlynkLib.Blynk(BLYNK_AUTH)

@blynk.on("connected")
def blynk_connected(ping):
print('Blynk ready. Ping:', ping, 'ms')

def runLoop():
while True:
blynk.run()
machine.idle()

Run blynk in the main thread:
runLoop()

from blynk-library-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.