Created
December 28, 2016 18:24
-
-
Save dermatthias/055a5540d03c8657d496035784449088 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import paho.mqtt.client as mqtt | |
import time | |
import json | |
import base64 | |
def on_connect(client, userdata, flags, rc): | |
print("Connected with result code " + str(rc)) | |
dev_eui = 'ZZZZZ' | |
app_id = 'YYYY' | |
access_key = 'ttn-account-v2.XXXXXX' | |
client = mqtt.Client() | |
client.on_connect = on_connect | |
client.username_pw_set(app_id, access_key) | |
client.connect('eu.thethings.network', 1883, 60) | |
client.loop_start() | |
while True: | |
time.sleep(5) | |
payload = json.dumps(dict(msg='hello world')) | |
channel = app_id + '/devices/' + dev_eui + '/up' | |
print(channel, payload) | |
client.publish(channel, payload) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment