emit, MQTT module and event name too long

Posted on
  • The MQTT module emits 'disconnected' when you call disconnect - https://github.com/espruino/EspruinoDocs­/blob/master/devices/MQTT.js#L167

    For me, this returns an error "event name too long".

    A quick look at Espruino's source code [https://github.com/espruino/Espruino/blo­b/f18509acff2a9fdfb8d7414f46b4e546e3be01­d3/src/jswrap_object.c#L484] suggests that an event name can be up to 12 characters long (16 is the length of the constant, minus 4 as in the line of code)

    'Disconnected' is 12 characters long, so I feel like it should work, so I'm not quite sure what's going on here.

  • Thanks, I'll take a look at this. I might just be able to totally remove that restriction - it seems a bit random converting back to a C string

  • Ok, just got it working with longer constants.

    I think the issue was (and it's a bit of a hack), jsvGetString fills the buffer up and terminates with a 0, and returns the amount of characters written in that buffer. However in order for it to be 'safe' when people just use it without checking, even if there are more characters than allowed it can still only return the size of the buffer - so you're effectively wasting one character at the end - if that gets used you just assume it overflowed, even if it might have 'just fitted'.

  • Great, thanks.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

emit, MQTT module and event name too long

Posted by Avatar for Moray @Moray

Actions