Closed iker190 closed 5 years ago
Which hardware/os do you have? Please also provide your script code.
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()
It's been working now for a week without any error. The program remains unchanged.
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()
I'm getting "Unexpected command: 41" error each time I start my program, sometimes the program starts correctly but it stops after a few hours (~2h). After that if I try to start the program again I get the error. I also get the same error when I try the readme example. I tried on a linux desktop computer and on a raspberry pi. I can see that command 41 is not implemented yet but I haven't seen anyone with my same issue. Could be a problem with my home network? What does the 41 command do? Thank you