or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
MQTT
MQTT was developed by Andy Stanford-Clark (IBM) and Arlen Nipper (Eurotech; now Cirrus Link) in 1999 for the monitoring of an oil pipeline through the desert.
The goals were to have a protocol, which is bandwidth-efficient and uses little battery power, because the devices were connected via satellite link and this was extremely expensive at that time.
The protocol uses a publish/subscribe architecture wich is event-driven and enables messages to be pushed to clients. The central communication point is the MQTT broker, it is in charge of dispatching all messages between the senders and the rightful receivers. Each client that publishes a message to the broker, includes a topic into the message.
The topic is the routing information for the broker. Each client that wants to receive messages subscribes to a certain topic and the broker delivers all messages with the matching topic to the client. Therefore the clients don’t have to know each other, they only communicate over the topic.
This architecture enables highly scalable solutions without dependencies between the data producers and the data consumers.
source
A topic is a simple string defined by the user that can have more hierarchy levels, which are separated by a slash.
Wilcards can also be used in sigle leves ej.
mdef/input/+/temperature
will return temperatures of all teams.Or in multilevels:
mdef/output/#
will return all outputs from all teams.MQTT on Arduino IDE
Open the Library manager in Arduino menu Sketch -> Include Library -> Manage Libraries and search for the PubSubClient library, install it.
You can find the full API documentation for the PubSubClient library here
For the first test you can load MQTT_esp8266 example from the library examples. In File→Examples→PubSubClient menu.
WiFi setup
Change WiFi settings and mqtt_server address.
Receiving data
If you are suscribing to a topic (for actuator nodes) change subscription topic name on line 94. And modify the callback function around line 70 to control your actuator.
Publishing data
If you are publishing data (sensor nodes), modify the code in the loop function (after line 110) to get your sensor reading and publish it, also remember t.