Skip to content

Commit

Permalink
Update send_data_iwatch.py
Browse files Browse the repository at this point in the history
Fix the hard-coded IP address
  • Loading branch information
bernar0507 authored Apr 9, 2023
1 parent 507a335 commit 346a624
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions mqtt-iwatch-wot/iwatch/send_data_iwatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import json
import iwatch_simulator
import time
import os
import socket

# Replace with your own values
MQTT_BROKER_ADDRESS = "IP_ADDRESS_MQTT"
MQTT_BROKER_PORT = 1883
THING_ID = "org.Iotp2c:iwatch"
MQTT_TOPIC = f"{THING_ID}/things/twin/commands/modify"
Expand All @@ -27,10 +28,13 @@ def send_data_to_ditto(iwatch_data):
client.on_connect = on_connect
client.on_disconnect = on_disconnect
client.on_publish = on_publish

# Get the IP address of the MQTT broker
broker_ip = socket.gethostbyname("mosquitto")

# Connect to the MQTT broker
client.username_pw_set(username='ditto', password='ditto')
client.connect(MQTT_BROKER_ADDRESS, MQTT_BROKER_PORT, 60)
client.connect(broker_ip, MQTT_BROKER_PORT, 60)

# Prepare the Ditto command payload
ditto_data = {
Expand Down

0 comments on commit 346a624

Please sign in to comment.