Blynk in UIFlow
-
Are the blynk blocks fully functional as is in the most recent version of UIFlow? I can receive from my device on my app, but I do not seem to be able to send to or receive any data on my device from my phone/app. I tried a simple text field and I tried a couple of sliders and they do not seem to transmit the data to the device. It could very easily be a user error. I was looking for more information on here and the only thing I saw was maybe in 1.52 or so, there was maybe an issue with where the init statement was getting placed.
Thanks
-
Is the only thing missing in the included blocks a blynk.run() statement? I see that in other coding examples, but I do not see this in any of the created code from UIFlow.
-
I have a M5Stack FIRE device and it also happens to me, I can send data to my phone, but my phone cannot to the device.
-
In UIFlow 1.7.1/1.7.2, there seems to be an inconsistency between Blockly (generated Python code) and the Blynk library. The following is the created Blockly code.
And the following is the generated Python code for M5Stack Core2.
from m5stack import * from m5stack_ui import * from uiflow import * from ble import blynk screen = M5Screen() screen.clean_screen() screen.set_screen_bg_color(0xFFFFFF) vr = None count = None vw = None value = None def blynk_write(): global vr, count, vw, value print('connected') pass def blynk_write(): global vr, count, vw, value print('disconnected') pass def blynk_write(*args): global vr, count, vw, value vr = args[0] count = count + 1 print([vr, count]) blynk.virtual_write(int(vr), count) pass def blynk_write(*args): global vr, count, vw, value vw, value = args[0], args[1] print([vw, value]) pass blynk.init('Blynk Test', '...token...', blynk.BLE) blynk.handle_event(blynk_write, 'connected') blynk.handle_event(blynk_write, 'disconnected') blynk.handle_event(blynk_write, 'write v*') blynk.handle_event(blynk_write, 'read v*') count = 0
I have modified as follows.
- make the event function name unique
- change the order of the arguments in blynk.handle_event
Then, it's works.
from m5stack import * from m5stack_ui import * from uiflow import * from ble import blynk screen = M5Screen() screen.clean_screen() screen.set_screen_bg_color(0xFFFFFF) vr = None count = None vw = None value = None def blynk_connected(): global vr, count, vw, value print('connected') pass def blynk_disconnected(): global vr, count, vw, value print('disconnected') pass def blynk_read(*args): global vr, count, vw, value vr = args[0] count = count + 1 print([vr, count]) blynk.virtual_write(int(vr), count) pass def blynk_write(*args): global vr, count, vw, value vw, value = args[0], args[1] print([vw, value]) pass blynk.init('Blynk Test', 'wbZdMJ8V1QCuYdePAqrlmt4iizSAX1j7', blynk.BLE) blynk.blynkBLE.ble.config(gap_name='Blynk Test') blynk.handle_event('connected', blynk_connected) blynk.handle_event('disconnected', blynk_disconnected) blynk.handle_event('write v*', blynk_write) blynk.handle_event('read v*', blynk_read) count = 0
-
I think this BLE Blynk library is similar to the one used in UIFlow.
https://github.com/vshymanskyy/blynk-library-python/blob/master/examples/hardware/PyCom_BLE.pyThere was a problem with a continuous call to blynk.virtual_write. blynk.virtual_write calls _write in class BlynkBLE, _write concatenates the data and sends the data when run() is called. The following code is part of class BlynkBLE.
def _write(self, data): self.bout += data def run(self): self.process() while len(self.bout): data = self.bout[:20] self.bout = self.bout[20:] print('<', data) self.tx.value(data)
If you call multiple blynk.virtual_write() in a row as follows, data1 and data2 will be concatenated, and when run() is called, the concatenated data will be sent.
blynk.virtual_write(1, data1) blynk.virtual_write(2, data2)
In this case, the iOS Blynk app was unable to get the second data. Therefore, I added the call "blynk._blynk.run()" immediately after blynk.virtual_write as shown below.
blynk.virtual_write(1, data1) blynk._blynk.run() blynk.virtual_write(2, data2) blynk._blynk.run()
-
@inasawa In this way, it works perfect.
-
@inasawa I am using the thonny editor for python code and it works great.
-
@inasawa Thank you very much for the information and help.