examples.lua 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. --
  2. -- Given all funcation names needed register to system
  3. --
  4. function register_hook()
  5. return "on_client_connected",
  6. "on_client_disconnected",
  7. "on_client_subscribe",
  8. "on_client_unsubscribe",
  9. "on_session_subscribed",
  10. "on_session_unsubscribed",
  11. "on_message_delivered",
  12. "on_message_acked",
  13. "on_message_publish"
  14. end
  15. ----------------------------------------------------------------------
  16. -- Callback Functions
  17. function on_client_connected(clientid, username, returncode)
  18. print("Lua: on_client_connected - " .. clientid)
  19. -- do your job here
  20. return
  21. end
  22. function on_client_disconnected(clientid, username, reason)
  23. print("Lua: on_client_disconnected - " .. clientid)
  24. -- do your job here
  25. return
  26. end
  27. function on_client_subscribe(clientid, username, topic)
  28. print("Lua: on_client_subscribe - " .. clientid)
  29. -- do your job here
  30. return topic
  31. end
  32. function on_client_unsubscribe(clientid, username, topic)
  33. print("Lua: on_client_unsubscribe - " .. clientid)
  34. -- do your job here
  35. return topic
  36. end
  37. function on_session_subscribed(clientid, username, topic)
  38. print("Lua: on_session_subscribed - " .. clientid)
  39. -- do your job here
  40. return
  41. end
  42. function on_session_unsubscribed(clientid, username, topic)
  43. print("Lua: on_session_unsubscribed - " .. clientid)
  44. -- do your job here
  45. return
  46. end
  47. function on_message_delivered(clientid, username, topic, payload, qos, retain)
  48. print("Lua: on_message_delivered - " .. clientid)
  49. -- do your job here
  50. return topic, payload, qos, retain
  51. end
  52. function on_message_acked(clientid, username, topic, payload, qos, retain)
  53. print("Lua: on_message_acked- " .. clientid)
  54. -- do your job here
  55. return
  56. end
  57. function on_message_publish(clientid, username, topic, payload, qos, retain)
  58. print("Lua: on_message_publish - " .. clientid)
  59. -- do your job here
  60. return topic, payload, qos, retain
  61. end