Design principles
Used components
- ArduinoNano5V
- NRF24L01+
- NRF24L01+ Adapter
- W5100 Ethernet
Wiring
Component | Pin | Wire | Pin | Component |
---|---|---|---|---|
NRF24L01+ Adapter | VCC | red | 5V | PowerSupply HLK-PM01 |
NRF24L01+ Adapter | GND | black | GND | PowerSupply HLK-PM01 |
NRF24L01+ Adapter | CE | white | D5 | ArduinoNano5V |
NRF24L01+ Adapter | CSN | orange | D6 | ArduinoNano5V |
NRF24L01+ Adapter | SCK | grey | A0 = 14 | ArduinoNano5V |
NRF24L01+ Adapter | M0 (MOSI) | yellow | A1 = 15 | ArduinoNano5V |
NRF24L01+ Adapter | M1 (MISO) | purple | A2 = 16 | ArduinoNano5V |
ArduinoNano5V | 5V | red | 5V | PowerSupply HLK-PM01 |
ArduinoNano5V | GND | black | GND | PowerSupply HLK-PM01 |
W5100 Ethernet | +5 | red | 5V | PowerSupply HLK-PM01 |
W5100 Ethernet | G | black | GND | PowerSupply HLK-PM01 |
W5100 Ethernet | CK (SCK) | orange | D13 | ArduinoNano5V |
W5100 Ethernet | M1 (MISO/SO) | green | D12 | ArduinoNano5V |
W5100 Ethernet | M0 (MOSI/SI) | yellow | D11 | ArduinoNano5V |
W5100 Ethernet | SS (SS/CS) | blue | D10 | ArduinoNano5V |
MQTT out
The MQTT topic resembles the serial protocol. You must define you preferred subscribe and publish prefix in the sketch. The topic is build like this:
PREFIX / NODE-ID / SENSOR-ID / MESSAGE-TYPE / ACK-FLAG / SUB-TYPE
With:
PREFIX: | Defined in the sketch as MY_MQTT_PUBLISH_TOPIC_PREFIX. Default: "mygateway1-out". |
---|---|
NODE-ID: | The unique id of the node that sends or should receive the message (address). |
SENSOR-ID: | Each node can have several sensors attached. This is the child-sensor-id that uniquely identifies one attached sensor. |
MESSAGE-TYPE: | Type of message sent - See table message-type at https://www.mysensors.org/download/serial_api_20. |
ACK-FLAG: | The ack parameter has the following meaning: Outgoing: 0 = unacknowledged message, 1 = request ack from destination node, Incoming: 0 = normal message, 1 = this is an ack message. |
SUB-TYPE: | Depending on messageType this field has different meaning. See tables below "presentation" at https://www.mysensors.org/download/serial_api_20 |
The topic has a payload: The actual data from the sensor, if any.
An example topic for data received from your gateway could look like this:
mygateway1-out/2/1/1/0/49
MQTT in
If you want to send data to your sensors use MY_MQTT_SUBSCRIBE_TOPIC_PREFIX defined in your sketch. Should be looking like this (using default sketch):
mygateway1-in/2/1/1/0/49
Code
Based on: https://github.com/mysensors/MySensors/blob/master/examples/GatewayW5100MQTTClient
Code at: MQTTGateway
Test
http://www.hivemq.com/demos/websocket-client/ Just fill in:
Host: | ds110j |
---|---|
Port: | 1883 |
And subscribe to "#".
Comments: