This commit is contained in:
Marcel Stör 2016-01-26 23:07:53 +01:00
commit 51352ed782
2 changed files with 51 additions and 10 deletions

View File

@ -78,12 +78,13 @@ none
Connects to the broker specified by the given host, port, and secure options.
#### Syntax
`mqtt:connect(host, port, secure, function(client))`
`mqtt:connect(host[, port[, secure[, autoreconnect]]][, function(client)])`
#### Parameters
- `host` host, domain or IP (string)
- `port` broker port (number)
- `port` broker port (number), default 1883
- `secure` 0/1 for `false`/`true`, default 0. [As per #539](https://github.com/nodemcu/nodemcu-firmware/issues/539#issuecomment-170298120) secure connections use TLS 1.2.
- `autoreconnect` 0/1 for `false`/`true`, default 0
- `function(client)` call back function for when the connection was established
#### Returns
@ -94,7 +95,7 @@ Connects to the broker specified by the given host, port, and secure options.
Setup [Last Will and Testament](http://www.hivemq.com/blog/mqtt-essentials-part-9-last-will-and-testament) (optional). A broker will publish a message with qos = 0, retain = 0, data = "offline" to topic "/lwt" if client does not send keepalive packet.
#### Syntax
`mqtt:lwt(topic, message, qos, retain)`
`mqtt:lwt(topic, message[, qos[, retain]])`
#### Parameters
- `topic` the topic to publish to (string)
@ -124,14 +125,14 @@ Registers a callback function for an event.
Publishes a message.
#### Syntax
`mqtt:publish(topic, payload, qos, retain, function(client))`
`mqtt:publish(topic, payload, qos, retain[, function(client)])`
#### Parameters
- `topic` the topic to publish to ([topic string](http://www.hivemq.com/blog/mqtt-essentials-part-5-mqtt-topics-best-practices))
- `message` the message to publish, (buffer or string)
- `qos` QoS level, default 0
- `retain` retain flag, default 0
- `function(client)` callback fired when PUBACK received
- `qos` QoS level
- `retain` retain flag
- `function(client)` optional callback fired when PUBACK received
#### Returns
`nil`
@ -141,12 +142,12 @@ Publishes a message.
Subscribes to one or several topics.
#### Syntax
`mqtt:subscribe(topic, qos, function(client, topic, message))`
`mqtt:subscribe(topic, qos[, function(client, topic, message)])`
#### Parameters
- `topic` a [topic string](http://www.hivemq.com/blog/mqtt-essentials-part-5-mqtt-topics-best-practices)
- `qos` QoS subscription level, default 0
- `function(client, topic, message)` callback fired when message received
- `function(client, topic, message)` optional callback fired when message received
#### Returns
`nil`

View File

@ -0,0 +1,40 @@
-- Support HTTP and HTTPS, For example
-- HTTP POST Example with JSON header and body
http.post("http://somewhere.acceptjson.com/",
"Content-Type: application/json\r\n",
"{\"hello\":\"world\"}",
function(code, data)
print(code)
print(data)
end)
-- HTTPS GET Example with NULL header
http.get("https://www.vowstar.com/nodemcu/","",
function(code, data)
print(code)
print(data)
end)
-- You will get
-- > 200
-- hello nodemcu
-- HTTPS DELETE Example with NULL header and body
http.delete("https://10.0.0.2:443","","",
function(code, data)
print(code)
print(data)
end)
-- HTTPS PUT Example with NULL header and body
http.put("https://testput.somewhere/somewhereyouput.php","","",
function(code, data)
print(code)
print(data)
end)
-- HTTP RAW Request Example, use more HTTP/HTTPS request method
http.request("http://www.apple.com:80/library/test/success.html","GET","","",
function(code, data)
print(code)
print(data)
end)