Please help me ,I need to update “data_bms_current” to show at Blynk. at “blynk.virtual_write(3, data_bms_current)”
import sys
import time
import serial
import struct
from binascii import unhexlify
import requests as req
import bluetooth
import BlynkLib
from bluetooth import *
from datetime import datetime
import sys
# Initialize Blynk
blynk = BlynkLib.Blynk('wTS9GrLjPCCm6kD6aZhM6ZTEZshN5P03')
# blynk = blynklib.Blynk(BLYNK_AUTH, server='blynk-cloud.com', port=80, ssl_cert=None,
# heartbeat=10, rcv_buffer=1024, log=print)
#if sys.version < '3':
# input = raw_input
bd_addr = "AA:BB:CC:A2:23:45"
port = 1
#sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
#sock.connect((bd_addr, port))
#sock.close()
#time.sleep(1)
#Define RS485 serial port
ser = serial.Serial(
port='/dev/rfcomm0',
baudrate = 9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout = 1)
#while True :
test='DBDB00000000'
try:
ser.write (test.decode('hex'))
except:
ser.close()
time.sleep(3)
Antw33 = ser.read(140)
#BMS current
data_bms_current = (Antw33.encode('hex') [(70*2):(73*2+2)])
try:
if int(data_bms_current,16)>2147483648:
data_bms_current=(-(2*2147483648)+int(data_bms_current,16))*0.1
print 'BMS current '+str(data_bms_current)+'A'
else:
data_bms_current = int(data_bms_current,16)*0.1
print 'BMS current '+str(data_bms_current)+'A'
except:
pass
# Register Virtual Pin
@blynk.VIRTUAL_READ(3)
def my_read_handler():
blynk.virtual_write(3, data_bms_current)
ser.close()
...