In this lesson, we will tell user to send MQTT message to MQTT broker

Parts required:
OSOYOO Wifi Shield x 1
Arduino UNO board x 1

Hardware connection:
Please insert OSOYOO wifi shield into Arduino UNO board, then use jumper caps to connect D4,D5 to E_TX and E_RX as following picture(the red square_:

Software library requirment:
You need installed following library:

1)WifiESP library
https://osoyoo.com/driver/WiFiEsp-master.zip

2)MQTT PubSubClient library
https://osoyoo.com/wp-content/uploads/samplecode/pubsubclient.zip

Software Sample sketch code:
Please download sample code from https://osoyoo.com/driver/wifi-iot/osoyoo-mqtt.zip

Open the code with Arduino IDE, you  need replace line 10,11 with your own Wifi SSID and password.

mqtt_server variable in Line 12 is the MQTT server you need to connect. We use free MQTT server “broker.mqttdashboard.com”, you can set this variable to your own MQTT broker if you like.

After running the code, the sketch code will send “Hello World ****” (**** is the time stamp)  to MQTT server under topic “OSOYO-Topic” (defined in line 1117) every 2 seconds.

You can use any MQTT client to connect to broker.mqttdashboard.com and subscribe topic “OSOYO-Topic” and get the message from our sample program.

We use free online MQTT client http://www.hivemq.com/demos/websocket-client/ and see the result as following: