开源软件名称(OpenSource Name):geekscape/mqtt_lua开源软件地址(OpenSource Url):https://github.com/geekscape/mqtt_lua开源编程语言(OpenSource Language):Lua 100.0%开源软件介绍(OpenSource Introduction):Lua MQTT client library (version 0.2 2012-06-01)This project is part of the Aiko Platform Contents
MQTT stands for "Message Queue Telemetry Transport", a protocol authored by Dr. Andy Stanford-Clark and Arlen Nipper. The protocol is a message-based, publish/subscribe transport layer, which is optimized for simple telemetry applications running on small micro-controllers, such as an Arduino, over low-bandwidth connections. MQTT libraries exist for most popular programming languages, so you can utilize MQTT on whatever server or device that you require. The Lua MQTT client library implements the client-side subset of the MQTT protocol specification 3.1. A good use-case for this library is running on constrained systems, such as OpenWRT, and acting as a gateway between non-MQTT clients and MQTT servers. The Aiko Platform uses this approach for aggregating non-TCP/IP devices and forwarding messages onto TCP/IP networks. An advantage of using Lua is that only a text editor is required for rapid development of simple MQTT client applications on platforms such as OpenWRT. In constrast, working with the C programming language would comparatively require more effort, due to requiring a cross-platform development environment. The Lua MQTT client library also runs (unmodified) on a Sony PlayStation Portable using the Lua Player HM (which requires your PSP to be able to run unsigned executables). Protocol implementation and restrictions ---------------------------------------- - Always assumes MQTT connection "clean session" enabled. - Supports connection last will and testament message. - Does not support connection username and password. - Fixed message header byte 1, only implements the "message type". - Only supports QOS (Quality Of Service) level 0. - Maximum payload length is 127 bytes (easily increased). - Publish message doesn't support "message identifier". - Subscribe acknowledgement messages don't check granted QOS level. - Outstanding subscribe acknowledgement messages aren't escalated. - Works on the Sony PlayStation Portable, using [Lua Player HM](http://en.wikipedia.org/wiki/Lua_Player_HM). Download -------- The Lua MQTT client library is cross-platform and should work on any platform that supports the Lua programming language and network sockets. Feedback and issues ------------------- Tracking is managed via GitHub ... Installation ------------ You may choose to install an MQTT server either on the same or a different system from the Lua MQTT client library, depending upon your deployment scenario.You can also install the Lua MQTT client library as part of the Aiko Platform run-time environment Prerequisites ...
On Linux, Lua and LuaRocks can be installed via your Linux distribution package manager. On Mac OS X, Lua and LuaRocks can be installed viarDarwin ports. After that, LuaSocket and PenLight can be installed via LuaRocks. Lua MQTT client library as a LuaRock ...
Lua MQTT client library (source code) from GitHub ...
mqtt_test: Test publish and receive messages on different topicsThis command periodically publishes a message on topic "test/1" and subscribes to the topic "test/2". The command exits when the message "quit" is published on topic "test/2".
mqtt_publish: Publish a single message to a specified topicThis command publishes a single message and then exits.
Only the --topic and --message parameters are required.
mqtt_subscribe: Subscribe to a topicThis command subscribes to a topic and listens indefinitely for messages. Use ^C (or similar) to stop execution.
Only the --topic parameter is required.
There are also a number of Lua MQTT client examples in the example/ directory. They can be run from the lua/ parent directory, as follow ...
Use the Lua require statement to load the MQTT client library ...
MQTT.Utility.set_debug(): Library debug console loggingThe following statement enables debug console logging for diagnosis.
MQTT.client.create(): Create an MQTT client instanceCreate an MQTT client that will be connected to the specified host.
The hostname must be provided, but both the port and callback function parameters are optional. This function returns an MQTT client instance that must be used for all subsequent MQTT operations for that server connection.
The callback function is defined as follows ...
MQTT.client:destroy(): Destroy an MQTT client instanceWhen finished with a server connection, this statement cleans-up all resources allocated by the client.
MQTT.client:connect(): Make a connection to an MQTT serverBefore messages can be transmitted, the MQTT client must connect to the server.
Each individual client connection must use a unique identifier. Only the identifier parameter is required, the remaining parameters are optional.
MQTT also provides a "last will and testament" for clients, which is a message automatically sent by the server on behalf of the client, should the connection fail.
MQTT.client:disconnect(): Transmit MQTT Disconnect messageTransmit an MQTT disconnect message to the server.
MQTT.client:publish(): Transmit MQTT publish messageTransmit a message on a specified topic.
MQTT.client:subscribe(): Transmit MQTT Subscribe messageSubscribe to one or more topics. Whenever a message is published to one of those topics, the callback function (defined above) will be invoked.
MQTT.client:handler(): Handle received messages, maintain keep-alive messagesThe handler() function must be called periodically to service incoming messages and to ensure that keep-alive messages (PING) are being sent when required. The default KEEP_ALIVE_TIME is 60 seconds, therefore handler() must be invoked more often than once per minute. Should any messages be received on the subscribed topics, then handler() will invoke the callback function (defined above).
MQTT.client:unsubscribe(): Transmit MQTT Unsubscribe messageUnsubscribe from one or more topics, so that messages published to those topics are no longer received.
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论