Navigation

    M5Stack Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. mb
    3. Topics
    M
    • Continue chat with mb
    • Start new chat with mb
    • Flag Profile
    • Profile
    • Following
    • Followers
    • Blocks
    • Topics
    • Posts
    • Best
    • Groups

    Topics created by mb

    • M

      [MicroPython] Add urllib.parse to base firmware to enable web services
      Features Wish List • • mb

      2
      0
      Votes
      2
      Posts
      4120
      Views

      M

      Adding upip to the firmware image would make developer's live much easier. How to manually install the urllib.parse library. Create folder /upip and add files upip.py and upip_utarfile.py manually. Install the library with upip: %cd /flash/upip import upip upip.install("micropython-urllib.parse", "/flash/lib") To get it working, remove re.py and ffilib.py from lib. Hat-tip to Andreas. Finally you can encode URL parameters for GET requests: %cd /flash/lib import urllib.parse urllib.parse.urlencode({"a":1, "b": 2}) => 'a=1&b=2'
    • M

      How to install MicroPython libraries? (HTTP GET with query parameters)
      Micropython • • mb

      4
      0
      Votes
      4
      Posts
      6597
      Views

      M

      Well, and there is always the option to just strip it down to the basics. # urlencode.py _ALWAYS_SAFE = frozenset(b'ABCDEFGHIJKLMNOPQRSTUVWXYZ' b'abcdefghijklmnopqrstuvwxyz' b'0123456789' b'_.-') _ALWAYS_SAFE_BYTES = bytes(_ALWAYS_SAFE) def quote(string, safe='/', encoding=None, errors=None): """quote('abc def') -> 'abc%20def' Each part of a URL, e.g. the path info, the query, etc., has a different set of reserved characters that must be quoted. RFC 2396 Uniform Resource Identifiers (URI): Generic Syntax lists the following reserved characters. reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" | "$" | "," Each of these characters is reserved in some component of a URL, but not necessarily in all of them. By default, the quote function is intended for quoting the path section of a URL. Thus, it will not encode '/'. This character is reserved, but in typical usage the quote function is being called on a path where the existing slash characters are used as reserved characters. string and safe may be either str or bytes objects. encoding must not be specified if string is a str. The optional encoding and errors parameters specify how to deal with non-ASCII characters, as accepted by the str.encode method. By default, encoding='utf-8' (characters are encoded with UTF-8), and errors='strict' (unsupported characters raise a UnicodeEncodeError). """ if isinstance(string, str): if not string: return string if encoding is None: encoding = 'utf-8' if errors is None: errors = 'strict' string = string.encode(encoding, errors) else: if encoding is not None: raise TypeError("quote() doesn't support 'encoding' for bytes") if errors is not None: raise TypeError("quote() doesn't support 'errors' for bytes") return quote_from_bytes(string, safe) def quote_plus(string, safe='', encoding=None, errors=None): """Like quote(), but also replace ' ' with '+', as required for quoting HTML form values. Plus signs in the original string are escaped unless they are included in safe. It also does not have safe default to '/'. """ # Check if ' ' in string, where string may either be a str or bytes. If # there are no spaces, the regular quote will produce the right answer. if ((isinstance(string, str) and ' ' not in string) or (isinstance(string, bytes) and b' ' not in string)): return quote(string, safe, encoding, errors) if isinstance(safe, str): space = ' ' else: space = b' ' string = quote(string, safe + space, encoding, errors) return string.replace(' ', '+') def quote_from_bytes(bs, safe='/'): """Like quote(), but accepts a bytes object rather than a str, and does not perform string-to-bytes encoding. It always returns an ASCII string. quote_from_bytes(b'abc def\x3f') -> 'abc%20def%3f' """ if not isinstance(bs, (bytes, bytearray)): raise TypeError("quote_from_bytes() expected bytes") if not bs: return '' if isinstance(safe, str): # Normalize 'safe' by converting to bytes and removing non-ASCII chars safe = safe.encode('ascii', 'ignore') else: safe = bytes([c for c in safe if c < 128]) if not bs.rstrip(_ALWAYS_SAFE_BYTES + safe): return bs.decode() try: quoter = _safe_quoters[safe] except KeyError: _safe_quoters[safe] = quoter = Quoter(safe).__getitem__ return ''.join([quoter(char) for char in bs]) def urlencode(query, doseq=False, safe='', encoding=None, errors=None): """Encode a dict or sequence of two-element tuples into a URL query string. If any values in the query arg are sequences and doseq is true, each sequence element is converted to a separate parameter. If the query arg is a sequence of two-element tuples, the order of the parameters in the output will match the order of parameters in the input. The components of a query arg may each be either a string or a bytes type. When a component is a string, the safe, encoding and error parameters are sent to the quote_plus function for encoding. """ if hasattr(query, "items"): query = query.items() else: # It's a bother at times that strings and string-like objects are # sequences. try: # non-sequence items should not work with len() # non-empty strings will fail this if len(query) and not isinstance(query[0], tuple): raise TypeError # Zero-length sequences of all types will get here and succeed, # but that's a minor nit. Since the original implementation # allowed empty dicts that type of behavior probably should be # preserved for consistency except TypeError: # ty, va, tb = sys.exc_info() raise TypeError("not a valid non-string sequence " "or mapping object")#.with_traceback(tb) l = [] if not doseq: for k, v in query: if isinstance(k, bytes): k = quote_plus(k, safe) else: k = quote_plus(str(k), safe, encoding, errors) if isinstance(v, bytes): v = quote_plus(v, safe) else: v = quote_plus(str(v), safe, encoding, errors) l.append(k + '=' + v) else: for k, v in query: if isinstance(k, bytes): k = quote_plus(k, safe) else: k = quote_plus(str(k), safe, encoding, errors) if isinstance(v, bytes): v = quote_plus(v, safe) l.append(k + '=' + v) elif isinstance(v, str): v = quote_plus(v, safe, encoding, errors) l.append(k + '=' + v) else: try: # Is this a sufficient test for sequence-ness? x = len(v) except TypeError: # not a sequence v = quote_plus(str(v), safe, encoding, errors) l.append(k + '=' + v) else: # loop over the sequence for elt in v: if isinstance(elt, bytes): elt = quote_plus(elt, safe) else: elt = quote_plus(str(elt), safe, encoding, errors) l.append(k + '=' + elt) return '&'.join(l) Then we can finally do a nicer GET with parameters: import urequests from urlencode import urlencode url = 'http://server.tld/path/to' params = {'key1': 'value1', 'key2': 'value2'} if params: url = url.rstrip('?') + '?' + urlencode(params, doseq=True) print(url) response = urequests.get(url)
    • M

      [Core2] Touch event handlers in [MicroPython]?
      Core 2 • • mb

      3
      0
      Votes
      3
      Posts
      5230
      Views

      F

      hello, i use the nice lvgl Lib to do That. create personalized button add event on the button example : from m5stack import * from m5stack_ui import * from uiflow import * import lvgl as lv screen = M5Screen() screen.clean_screen() screen.set_screen_bg_color(0x00000) lv.init() # create screen scr = lv.obj() # set Background screen scr.set_style_local_bg_color(scr.PART.MAIN, lv.STATE.DEFAULT, lv.color_hex(0x000000)) # create button btn = lv.btn(scr) btn.set_size(80, 80) # change style btn.set_style_local_bg_color(scr.PART.MAIN,lv.STATE.DEFAULT, lv.color_hex(0x0000ff)) styleButton = lv.style_t() # create style styleButton.set_bg_color(lv.STATE.DEFAULT, lv.color_hex(0x0000ff)) styleButton.set_radius(lv.STATE.DEFAULT, 0); styleButton.set_border_color(lv.STATE.DEFAULT, lv.color_hex(0x0000ff)) btn.add_style(btn.PART.MAIN,styleButton) #define this style # callback action def action(btn, event): global src if(event == lv.EVENT.CLICKED): btn.set_style_local_bg_color(btn.PART.MAIN, lv.STATE.DEFAULT, lv.color_hex(0xffffff)) btn.set_style_local_border_color(btn.PART.MAIN, lv.STATE.DEFAULT, lv.color_hex(0xffffff)) # define callback btn.set_event_cb(action) # load the screen lv.scr_load(scr) best regards Thomas
    • M

      [Core2] How to download JPG from web and display it on screen?
      Core 2 • • mb

      7
      0
      Votes
      7
      Posts
      9857
      Views

      M

      Here we go, easy work-around the faulty lcd.image(): from m5stack import * buffer = open("/sd/images/test.jpg").read() lcd.image_buff(lcd.CENTER, lcd.CENTER, buffer)
    • M

      [UIFlow] [Core/Core2] Add image block to show images like JPG on display
      Features Wish List • • mb

      2
      0
      Votes
      2
      Posts
      2805
      Views

      M

      Ok, I now found the image function on the left side of the Core in UIFlow. I was looking for it in the regular list of blocks, especially in "Graphic". from m5stack import * from m5stack_ui import * screen = M5Screen() screen.clean_screen() screen.set_screen_bg_color(0xFFFFFF) image0 = M5Img("/sd/images/sled150.png", x=0, y=0, parent=None) It would be great if it could also show JPG files, they still seem to be more common. Note that lcd.image() can display JPG files, but it crashes loading from micro SD card.
    • M

      [Bug] Core2 loads JPG from flash but crashes with image from micro SD card
      Micropython • • mb

      10
      0
      Votes
      10
      Posts
      11492
      Views

      M

      Here we go, easy work-around for the faulty lcd.image(): from m5stack import * buffer = open("/sd/images/test.jpg").read() lcd.image_buff(lcd.CENTER, lcd.CENTER, buffer)
    • M

      How to structure MicroPython with multiple files in UIFlow?
      UIFlow • • mb

      3
      0
      Votes
      3
      Posts
      3652
      Views

      @mb Highly recommend Thonny, you should try it out :)
    • M

      How to wait on multiple events, in parallel?
      UIFlow • • mb

      3
      0
      Votes
      3
      Posts
      2817
      Views

      M

      Excellent, thanks @world101 !
    • M

      Enable "back button" or "cancel button" in UIFlow main menu on device
      UIFlow • • mb

      4
      0
      Votes
      4
      Posts
      4113
      Views

      P

      I'm not sure if this helps, but when you are in M5Burner and you flash your Core2, next to the "Burn" button there is a "Configuration" button. In the popup, if you change the "Start Mode", does that get you out of the UiFlow screen on the Core2?
    • M

      M5Burner: enable setting WiFi on "advanced" devices like Core2
      SOFTWARE • • mb

      3
      0
      Votes
      3
      Posts
      3112
      Views

      M

      Thanks @felmue, I just updated M5Burner to the latest version and now it works :-)
    • M

      Recommendation @ M5Stack: provide instructions and required screws
      FACES Kit • • mb

      3
      0
      Votes
      3
      Posts
      3732
      Views

      M

      Two negative impressions with Core2 and FACE-RFID: When booting the Core2, it creates strange noise through the speaker for about 3 seconds When off, there is a constant quiet noise through the speaker when USB is connected
    • M

      Image swipe and snap-to-grid on Core 2 touchscreen?
      Core 2 • • mb

      2
      0
      Votes
      2
      Posts
      2559
      Views

      P

      @mb The m5button engine supports swipe gestures and the sprite engine can animate your graphics. Not aware of any m5 animation engines that handle that but maybe have a look at the Raphael animation engine - its very neat and might inspire you to port it for m5 sprite. Could also look at bounce.js - the maths to calculate easing is not complicated.
    • M

      Core2 Internet Radio - stream WAV/MP3/AAC from Internet to Core2 speaker?
      UIFlow • • mb

      1
      0
      Votes
      1
      Posts
      1948
      Views

      No one has replied

    • M

      UIFlow functions for touch and swipe on Core2?
      UIFlow • • mb

      1
      1
      Votes
      1
      Posts
      2174
      Views

      No one has replied

    • M

      RFID RC522 Panel for M5 Faces - without screws?
      Modules • • mb

      3
      0
      Votes
      3
      Posts
      2763
      Views

      M

      It would be nice if M5Stack can include those screws in the package. Nothing much you can do with a "Faces RFID" than screw it on a "Faces II Bottom Board". The "Standing Base" also includes the required screws to make it functional.
    • M

      UiFlow (web) requests wrong firmware update
      UIFlow • • mb

      3
      0
      Votes
      3
      Posts
      2985
      Views

      Hello, are you experiencing same issue with the desktop IDE? I'll note it down and look into it.
    • M

      How to exit Core2 setup Wi-Fi Config?
      UIFlow • • mb

      7
      0
      Votes
      7
      Posts
      7593
      Views

      @mb It doesn't show internet connectivity because the M5Stack device is operating on AP mode (no internet connection) it expects you to open your browser and enter the IP address 192.168.4.1 so you could give it your wifi credentials, once the M5Stack is connected to your wifi network you can start using it using UIFlow
    • M

      Create Thread for animation?
      UIFlow • • mb

      4
      0
      Votes
      4
      Posts
      3400
      Views

      Hi @mb yes, I suppose you could use a global variable, but timers also allow to be started and stopped. So you could start the timer with the animation, do the http request and when it's done stop the timer again. Cheers Felix
    • M

      UIFlow initiates AtomMatrix not correct when switching
      UIFlow • • mb

      8
      0
      Votes
      8
      Posts
      8513
      Views

      Looks like you got it working, but what I was referring to with the Execute block was adding the full command like this to see if it would override the first. In the Python tab it looks like the command duplicated. I don't have the AtomQR to test with, so I'm not sure if this works or not... However, I found another workaround without the Execute block. After loading the AtomicQR example flow, then switch from Atom-Lite to Atom-Matrix in the settings, it will indeed add rgb.set_screen([]) on the Python tab. This is the bug. If you just select one of the 25 LED squares in the UI editor to change it to white, then select the same square again to change it back to black. Check the Python tab again and it will now show rgb.set_screen([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]) automatically. If you save that as a new program (ex: Atomic_QR-Matrix), the next time you load the file, it should have the Matrix as the hardware type and the correct rgb.set_screen command in the python tab.
    • M

      Please provide UIFlow source code for ToF Hat
      UIFlow • • mb

      2
      0
      Votes
      2
      Posts
      2824
      Views

      thank you feedback. now it fixed. you could use the new firmware version UIFlow 1.6.5.1