Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this user
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
kaurm105
/
MQTT
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
1
Projects
0
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Projects
Security
Insights
Files
MANRAJ-PREET-KAUR
Lovepreet Individual contribution
Lovepreet kaur (coding)
MQTT.docx
README.md
Screenshot 2024-07-29 103309.png
Screenshot 2024-07-30 144825.png
Screenshot 2024-07-30 222035.png
Screenshot 2024-07-30 232934.png
Screenshot 2024-07-30 233608.png
Screenshot 2024-07-31 094030.png
Screenshot 2024-07-31 105451.png
Screenshot 2024-07-31 111609.png
Screenshot 2024-07-31 203035.png
Breadcrumbs
MQTT
/
Lovepreet Individual contribution
Blame
Blame
Latest commit
History
History
37 lines (28 loc) · 1.31 KB
Breadcrumbs
MQTT
/
Lovepreet Individual contribution
Top
File metadata and controls
Code
Blame
37 lines (28 loc) · 1.31 KB
Raw
# Publisher function for energy def publish_energy_data(client): while True: energy_usage = random.uniform(0.5, 2.0) # Simulate energy usage in kWh message = f"{energy_usage:.2f}" client.publish(energy_topic, message) print(f"Published Energy: {message} kWh") time.sleep(5) # Publish every 5 seconds # Subscriber callback def on_message(client, userdata, message): topic = message.topic payload = message.payload.decode() if topic == energy_topic: energy_usage = float(payload) print(f"Received Energy: {energy_usage} kWh") if energy_usage > 1.5: print("High energy usage detected! Turning off non-essential devices.") else: print("Energy usage is within the normal range.") elif topic == temperature_topic: temperature = float(payload) print(f"Received Temperature: {temperature} °C") # Add any specific handling for temperature data here ( manraj preet and lovepreet (me) ) worked together on this topic # Run the publisher functions in separate threads energy_thread = threading.Thread(target=publish_energy_data, args=(publisher_client,)) temperature_thread = threading.Thread(target=publish_temperature_data, args=(publisher_client,)) energy_thread.start() temperature_thread.start()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
You can’t perform that action at this time.