---
# System prepended metadata

title: IOT-HW3
tags: [hw, iot, thu]

---

###### tags: `iot` `hw` `thu`
{%hackmd theme-dark %}

# IOT-HW3

## IMAGES
1. Use CLI to send message:
![](https://i.imgur.com/2lGlsaZ.png)

2. Use python code to send message:
![](https://i.imgur.com/rhtYO2g.png)


## CODE
``` python
import paho.mqtt.client as paho


message = "------------------------------\nTesting MQTT Server in Python.\n------------------------------"
broker="152.70.108.105"
port=1883
def on_publish(client,userdata,result): #create function for callback
    print("Data published successfully! \n")
    pass
client1= paho.Client("MQTT Tester")             #create client object
client1.on_publish = on_publish             #assign callback function
client1.connect(broker,port)                    #establish connection
ret= client1.publish("test/mqtt", message)           #publish message
```
