• 0 Votes
    4 Posts
    2k Views
    N
    @robert-hh Thanks for that (and your assistance on my other question). I would be interested in your thoughts on how the "main" thread would check these flags as that goes back into using some kind of event/interrupt to know the timer/sensor readings have read something in. My first thoughts would be a while loop with a sleep count and checking periodically but feels like that is not the correct way to go about it. At this stage I am currently working with two or three period alarms executed from the "main" thread and a single secondary thread that is in a while loop and constantly sleeping looking for values at certain intervals which it then does the "heavy" processing and sending. @crumble - Yes I must admit I need to get out of some of my older habits to focus more on efficiency than simplicity/readability. However, I must admit I have been struggling to find material on how Micropython, specifically, works with allocation of memory for objects/variables/functions and what is the most efficient practice. Most examples go back to pure Python requiring multiple libraries to do memory statistics, even then not actually demonstrating what is the best way. Simple questions as to how the GC works, if I need to set variables to 'None' at the end of a function, or the use of a list over three distinct variables. The only way I am really finding it is by doing it both ways and testing it with gc.mem_free() which is time consuming and feels more like guess work. Would be interested on your point 4 about modules and compiling at boot time.
  • RuntimeError: maximum recursion depth exceeded?

    runtime error recursion
    4
    0 Votes
    4 Posts
    2k Views
    S
    Quick update. In esp32/mptask.h there exists: #define MICROPY_TASK_PRIORITY MP_THREAD_PRIORITY #define MICROPY_TASK_STACK_SIZE (8 * 1024) #define MICROPY_TASK_STACK_SIZE_PSRAM (12 * 1024) #define MICROPY_TASK_STACK_LEN (MICROPY_TASK_STACK_SIZE / sizeof(StackType_t)) I believe this is where we could increase the stack size, but I am unsure of the sanity and practicality of this... Thoughts?
  • Connecting to Eduroam

    eduroam nano gateway python
    10
    0 Votes
    10 Posts
    3k Views
    D
    @thomand1000 Unfortunately I didn't get it entirely fixed, the best theory is that the Eduroam has a UDP timeout feature, I did find a work around that has been working consistently, it gives a maximum of about 30 seconds downtime every 31minutes. The few things I changed are in the nanogateway.py file for the gateway example: After 1900 seconds the message "Failed to pull downlink packets from server" would occur so I put a machin.reset() in: def _pull_data(self): token = uos.urandom(2) packet = bytes([PROTOCOL_VERSION]) + token + bytes([PULL_DATA]) + ubinascii.unhexlify(self.id) with self.udp_lock: try: self.sock.sendto(packet, self.server_ip) except Exception as ex: machine.reset() self._log('Failed to pull downlink packets from server: {}', ex) And every 4-5th restart it would just not connect so I did a simple timer reset in the wifi connection: def _connect_to_wifi(self): count = 0 self.wlan.connect(ssid='eduroam', auth=(WLAN.WPA2_ENT, 'Username', 'Password'), identity='Username', timeout = 30) while not self.wlan.isconnected(): utime.sleep(1) count = count + 1 print(count) if count >= 30: machine.reset() self._log('WiFi connected to: {}', self.ssid) Hopefully one day I'll be able to get the UDP timeout thing properly fixed, but they don't change things like this in a hurry for a student haha.
  • Bytearray() and structures for floating point values

    bytearray floating point
    7
    0 Votes
    7 Posts
    6k Views
    S
    I found an answer. The function in Python by default packs the four bytes in little endian format. JavaScript expects big endian. By merely changing data = bytearray(struct.pack("f", vt)) to data = bytearray(struct.pack(">f", vt)) the unpack at the other end was simple. Java Script function decodeFloat(data1) { var binary = parseInt(data1, 16).toString(2); if (binary.length < 32) binary = ('00000000000000000000000000000000'+binary).substr(binary.length); var sign = (binary.charAt(0) == '1')?-1:1; var exponent = parseInt(binary.substr(1, 8), 2) - 127; var significandBase = binary.substr(9); var significandBin = '1'+significandBase; var i = 0; var val = 1; var significand = 0; if (exponent == -127) { if (significandBase.indexOf('1') == -1) return 0; else { exponent = -126; significandBin = '0'+significandBase; } } while (i < significandBin.length) { significand += val * parseInt(significandBin.charAt(i)); val = val / 2; i++; } return sign * significand * Math.pow(2, exponent); } // example use data = '408df220' // is floating point value 4.43580627441406255 value = decodeFloat(data); log.console('Value=', value); The code above is from https://stackoverflow.com/questions/4414077/read-write-bytes-of-float-in-js From a great website application at https://gregstoll.dyndns.org/~gregstoll/floattohex/ I produced the image below [image: float.png]
  • MQTT Reconnect How To ???

    mqtt mqtt connect wipy2.0
    2
    0 Votes
    2 Posts
    1k Views
    L
    @pturcotte You should got exception from some sending code and then you can catch it and reconnect to the network https://forum.pycom.io/post/14510
  • ISL29125 RGB Sensor python library

    python rgb sensor sparkfun
    1
    0 Votes
    1 Posts
    757 Views
    No one has replied
  • CCS811 library ?

    ccs811 micropython i2c
    6
    0 Votes
    6 Posts
    2k Views
    ledbelly2142L
    @jiemde Thanks! I forked it. Cheers!
  • Asyncio and micropython

    wipy 2
    8
    0 Votes
    8 Posts
    3k Views
    on4aaO
    I saw you efforts over at #112. Great work!
  • MODBUS Libraries

    modbus
    14
    0 Votes
    14 Posts
    4k Views
    Charly86C
    thanks @daniel
  • Receive data on lopy through serial

    serial lopy
    48
    0 Votes
    48 Posts
    21k Views
    robert-hhR
    @monersss At the moment, with my example, that happens when you get a timeout. But again, that would require some "out-of-band" signaling, meaning: in addition to the "payload", the jpg file, some control information must be exchanged. And that is part of a protocol. That could be pretty simple. If I grab one out of the air, it could be: Define record types, where the first letter defines the type of the record, followed by 3 bytes record length, followed by the payload, like: 'fnnn': filename (of length nnn) 'd128': data 'x000': done You would first receive 4 bytes, decode type and length, and then receive further 'length' bytes. And for every record received, your LoPy would send a confirmation, like the three bytes: "ok!" or "bad", in case of errors (or just a single byte). That would implement flow control and the EOF signal. It does not have other elements like check sums and sequence control. But you might not need that.
  • Configuration class

    python
    3
    0 Votes
    3 Posts
    923 Views
    robert-hhR
    @misterlisty Besides that setx() should store the value, the other way of doing that is with decorators: class Status(object): def __init__(self): self.__x = 2 @property def x(self): return self.__x @x.setter def x(self, val): self.__x=val a=Status() print(a.x) a.x=1001 print(a.x)
  • wlan.scan() errno 12 ENOMEM

    wifi memoryerror esp32 micropython
    2
    0 Votes
    2 Posts
    1k Views
    robert-hhR
    @dhblumenfeld1989 This cannot be the full script. At least a two lines are missing upfront, like: from network import WLAN wlan = WLAN(mode=WLAN.STA) And as a side note: The flash size you get with uos.getfree() is not relevant for memory errors. These are caused by RAM shortage. The size of free RAM is told by gc.mem_free(). And for all people trying to help it is useful to know the firmware version, which can be obtained by uos.uname().
  • Removing the brackets from the (None, None) on the node

    pytrack micropython
    1
    0 Votes
    1 Posts
    637 Views
    No one has replied
  • bluetooth.service and characteristic correlation

    ble
    2
    0 Votes
    2 Posts
    1k Views
    J
    @misterlisty When you do this: b'1234567890123456') You're creating a list of bytes based on the ASCII value of each digit (1 = 0x31, 2=0x32 3=0x33 etc) Your phone however shows you the hexadecimal representation of each byte. It also has a different byte ordering but you can see the b'123...' in "...33-3231" - it's just in reverse order See my previous post on how to produce services that look as you expect: https://forum.pycom.io/post/3279
  • List of OSErrors

    oserror wipy micropython
    3
    0 Votes
    3 Posts
    1k Views
    T
    See my answer regarding oserror from tls in the post: https://forum.pycom.io/topic/2164/lopy-http-post-request-oserror/9
  • publish/subscribe without MQTT

    pubsub
    3
    0 Votes
    3 Posts
    956 Views
    A
    Good idea as such, however, I want to keep cost and complexity down. Ended up reading from i2c and uart, accepting new tcp connection, adding new connection to a list (socket, address-port tuple)), looping through every tcp connection and sending the message. If sending fails, remove that particular (socket, addr) from list and close socket. It works well, and all without threads. It looks that the speed is good enough, and I'm not losing any packets. Thanks!
  • Only one PWM timer?

    Moved
    4
    0 Votes
    4 Posts
    1k Views
    sorenS
    has this been fixed by now?
  • Oracle MySQL connector.

    wypy sypy mysql
    3
    0 Votes
    3 Posts
    926 Views
    A
    @crumble That's a shame. It just means I have to write a connector on the server. I wonder how it's implmented with the Pybytes!
  • urequests with ussl causes an OSError

    urequests oserror post
    6
    1 Votes
    6 Posts
    2k Views
    D
    @this-wiederkehr You've got the point. I've tried this and finally, it works without any error. Thanks a lot.
  • 0 Votes
    3 Posts
    1k Views
    J
    @jcaron Thanks for your reply. 1.) I would say everything below 5 seconds is acceptable. 2. / 3.) This question is hard to answer, since I will try the device with different types of applications so the capacity of the batteries will strongly vary. The battery life should be as long as possible. I also found the machine.idle and machine.sleep in http://docs.micropython.org/en/latest/wipy/library/machine.html. Given the description machine.sleep should work if I trigger the LoPy through Wifi. Is that correct? Thanks in advance.

Pycom on Twitter