WiPy 2.0 + Blynk



  • So I'm new to python and the blynk system but figured it couldn't be that difficult. However I'm getting stuck at importing the library. The steps I took:

    1. Update Firmware: 1.7.2.b1
    2. Build the FTP connection with Pymakr plugin on the Atom IDE
    3. Update the boot.py to connect to home wifi network (suc. connection)
    4. Run the main.py code over the connection

    The Code I want to run is from the example and tragically simple:

    import BlynkLib
    import time

    BLYNK_AUTH = "my token"

    blynk = BlynkLib.Blynk(BLYNK_AUTH)
    def v3_write_handler(value):
    print('Current slider value: {}'.format(value))
    blynk.add_virtual_pin(3, write=v3_write_handler)
    blynk.run()

    However on bootup I get the following message:
    Traceback (most recent call last):                                                                             
      File "main.py", line 2, in <module>                                                                          
      File "/flash/lib/BlynkLib.py", line 126, in <module>                                               
      File "/flash/lib/BlynkLib.py", line 127, in HwPin                                                     
    AttributeError: type object 'Timer' has no attribute 'B'

    When I try to run the program I get a different error:
    AttributeError: 'module' object has no attribute 'Blynk'
    Now I checked and the library does include the class Blynk and only shared import is "time".

    I''m using Atom IDE pymakr plugin on MicroPython v1.8.6
    If someone could help me solve this it would be awesome



  • @BitNide
    I got it "working" ... at least 02_virtual_read.py.

    In BlynkLib.py I changed _TimerMap = {}.

    Rationale: Presumably the HwPin class is not used by virtual pins. Then it would not be surprising if they are not affected by the change. Not sure yet if I even care about non-virtual pins.



  • This post is deleted!


  • YAY I FIXED IT

    for anyone wanting to use the library and connect to blink.

    in the MachineStub.py file remove line 203+
    in the BlynkLib.py file change all the instances of:
    time.sleep_ms -> MachineStub.sleep_ms
    time.ticks_ms -> MachineStub.ticks_ms
    time.ticks_diff -> MachineStub.ticks_diff

    be sure to import both the MachineStub and machine module in the BlynkLib.py module



  • how would I go about migrating it?

    Also I have been debugging a bit further and found the following code which seems to be at fault:

    timeModule = sys.modules["time"]

    setattr(timeModule, 'sleep_ms', sleep_ms)
    setattr(timeModule, 'ticks_ms', ticks_ms)
    setattr(timeModule, 'ticks_diff', ticks_diff)

    I get the error : "keyError: time"

    It seems to me like the time module does not accapt the additional attributes.



  • @BitNide
    Code is for wipy1.0 not for wipy2.0
    You must migrate it or wait for pycom for migrating (if it is somehow in progress)



  • could the problem be in the HwPin class using machine.Timer.B? resulting in import error?



Pycom on Twitter