1. 05 Jan, 2021 1 commit
    • Nathaniel Wesley Filardo's avatar
      First round of MQTT fixes (#3360) · c695a451
      Nathaniel Wesley Filardo authored
      * mqtt: remove concept of connection timeout
      
      Just rely on the network stack to tell us when things have gone south.
      
      * mqtt: remove write-only mqtt_state.port field
      
      * mqtt: drop useless conditional
      
      * mqtt: decouple message sent flag from timer
      
      * mqtt: reconnect callback does not need to hang up
      
      The network stack has certainly done that for us at this point.
      Similarly, since we're about to call mqtt_socket_disconnected, don't
      bother unregistering the timer here, either.
      
      * mqtt: don't tick once per second
      
      Set the timer for the duration of the wait and cancel it on the other side.
      
      * mqtt: defer message queue destruction to _disconnect
      
      We're going to want to publish a disconnect message for real, so doing
      this in _close does no one any favors
      
      * mqtt: miscellaneous cleanups
      
      No functional change intended
      
      * mqtt: close() should send disconnect message for real
      
      This means waiting for _sent() to fire again before telling the network
      stack to disconnect.
      
      * mqtt: tidy connect and dns
      
      - Push the self-ref to after all allocations and error returns
      
      - Don't try to extract IPv4 from the domain string ourselves, let the
        resolver, since it can
      
      - Don't try to connect to localhost.  That can't possibly work.
      
      * mqtt: common up some callback invocations
      
      * mqtt: don't retransmit messages on timeout
      
      There's no point in retransmitting messages on timeout; the network
      stack will be trying to do it for us anyway.
      
      * mqtt: remove unnecessary NULL udata checks
      
      * mqtt: hold strings in Lua, not C
      
      Eliminates a host of C-side allocations.
      
      While here, move the rest of the mqtt_connect_info structure out to its
      own thing, and pack some flags using a bitfield.
      
      * mqtt: mqtt_socket_on use lua_checkoption
      
      * mqtt: slightly augment debug messages
      
      These changes have made some debugging ever so slightly easier.
      c695a451
  2. 09 Jun, 2020 1 commit
    • Nathaniel Wesley Filardo's avatar
      WIP: MQTT fixes (#2986) · 30f706fb
      Nathaniel Wesley Filardo authored
      * mqtt: expose "connfail" callback via :on()
      
      This makes it just like all the other callbacks in the module and is a
      revision of behavior called out in
      https://github.com/nodemcu/nodemcu-firmware/pull/2967
      
      * mqtt: clarify when puback callback fires
      
      * mqtt: Don't reference stack buffers from the heap
      
      The confusingly-named "mqtt_connection_t" object is just a triple of
        - a serialized mqtt message pointer and length
        - a buffer pointer (to which the above can be written)
        - a message identifier
      
      The last of these must be passed around the mqtt state machine, but the
      first two are very local and the buffer is always sourced from the C
      stack.  Unfortunately, because the entire structure is persisted in the
      heap, some callers assume that they can always use the structure without
      reinitialization (see mqtt_socket_close), which will trash the C stack.
      
      Sever the pairing between message id and local state, punt the local
      state entirely out of the heap, and rename things to be less confusing.
      30f706fb
  3. 23 Jul, 2019 2 commits
  4. 21 Jul, 2019 1 commit
    • Johny Mattsson's avatar
      Major cleanup - c_whatever is finally history. (#2838) · 526d21da
      Johny Mattsson authored
      The PR removed the bulk of non-newlib headers from the NodeMCU source base.  
      app/libc has now been cut down to the bare minimum overrides to shadow the 
      corresponding functions in the SDK's libc. The old c_xyz.h headerfiles have been 
      nuked in favour of the standard <xyz.h> headers, with a few exceptions over in 
      sdk-overrides. Again, shipping a libc.a without headers is a terrible thing to do. We're 
      still living on a prayer that libc was configured the same was as a default-configured
      xtensa gcc toolchain assumes it is. That part I cannot do anything about, unfortunately, 
      but it's no worse than it has been before.
      
      This enables our source files to compile successfully using the standard header files, 
      and use the typical malloc()/calloc()/realloc()/free(), the strwhatever()s and 
      memwhatever()s. These end up, through macro and linker magic, mapped to the 
      appropriate SDK or ROM functions.
      526d21da
  5. 17 Feb, 2019 1 commit
  6. 30 Nov, 2018 1 commit
    • Johan Ström's avatar
      Handle large/chunked/fragmented MQTT messages properly (#2571) · 2d958750
      Johan Ström authored
      * MQTT: handle large/chunked/fragmented messages properly
      
      If a message spans multiple TCP packets it must be buffered before
      delivered to LUA. Prior code did not do this at all, so this "patch"
      really adds proper handling of fragmented MQTT packets.
      This could also occur if multiple small messages was sent in a
      single TCP packet, and the last message did not completely fit in that
      packet.
      
      Introduces a new option to the mqtt.Client constructor:
      max_publish_length which defaults to 1024
      
      Introduces a new 'overflow' callback.
      
      Fixes issue #2308 and proper fix for PR #2544.
      
      * mqtt.md: clarified heap allocation
      
      * mqtt: ensure ack is sent for overflowed publish
      
      If QoS is used we should still acknowledge that we received it, or server might retransmit it later.
      2d958750
  7. 17 Mar, 2018 1 commit
  8. 19 Apr, 2017 1 commit
  9. 20 Mar, 2016 1 commit
  10. 10 Mar, 2016 1 commit
  11. 06 Mar, 2016 1 commit
    • jfollas's avatar
      MQTT Client - CONNACK processing · 0abe2fe9
      jfollas authored
      - Process the CONNACK message received from the broker after Connect
      - Provide feedback to Lua via failure callback on client:connect()
      - Also provide failure information for other situations not covered by CONNACK
      0abe2fe9
  12. 23 Jan, 2016 1 commit
  13. 31 Mar, 2015 1 commit
  14. 29 Mar, 2015 1 commit
  15. 31 Jan, 2015 1 commit
  16. 23 Jan, 2015 1 commit