def init_mqtt(self): import euglena_board board = euglena_board.Euglena_board() mqtt_account = board.get_mqtt_account() self.mqtt = mqtt.MQTT('esp32-' + ubinascii.hexlify(os.urandom(4)).decode()) self.mqtt.username_pw_set(mqtt_account['username'], mqtt_account['password']) self.mqtt_username = mqtt_account['username'] self.mqtt.on_message(self.pp) self.mqtt.connect_async(board.get_mqtt_host(), port=8882) self.mqtt.init()
def __init__( self ): self.__bucketName = '' self.__files = defaultdict( ) self.__userName = '' self.__actionName = '' self.__taskName = '' self.__path = '' self.__nodeID = requests.get( "http://localhost:4001/info" ).json()['Name'] # print("CHECK: ", self.__nodeID ) # Get the reouserce self.s3Obj = s3.S3() self.mqttObj = mqtt.MQTT() self.mqttObj.start() self.updateTopic = "Updates"
def __init__(self): import euglena_board global pyscript_mqtt_client board = euglena_board.Euglena_board() mqtt_account = board.get_mqtt_account() pyscript_mqtt_client = mqtt.MQTT( 'esp32-' + ubinascii.hexlify(os.urandom(4)).decode()) self.mqtt = pyscript_mqtt_client self.mqtt.username_pw_set(mqtt_account['username'], mqtt_account['password']) self.mqtt_username = mqtt_account['username'] self.remote_username = board.get_mqtt_remote_username() self.mqtt.on_message(self.on_mqtt_message) self.mqtt.connect_async(board.get_mqtt_host(), port=8882) self.mqtt.init() Timer.Alarm(handler=self.mqtt_publish_status, s=15, ms=0, us=0, periodic=1) self.err = None self.err_count = 0
# for midi generation from pyo import * import random # the config and mqtt modules are in a bad place atm :/ import sys sys.path.append('./mqtt/') import config import mqtt myHostname = config.getHostname() deploymenttype = config.getDeploymentType() DEVICENAME = config.getDevicename() mqttHost = config.getValue("mqtthostname", "localhost") hostmqtt = mqtt.MQTT(mqttHost, myHostname, DEVICENAME) hostmqtt.loop_start() # use the background thread sounddir = config.getValue("sounddir", "../../sounds/") testsound = config.getValue("testsound", "test.wav") isMuted = False def main(): s = Server(duplex=0) s.setOutputDevice(pa_get_default_output()) s.boot() s.start() time.sleep(1)
sta.active(True) # 尝试打开ssid文件获取之前配置的ssid try: with open('ssid.py', 'r') as fp: ssid = fp.readline() password = fp.readline() sta.connect(ssid, password) time.sleep(5) except: pass # 如果可以联网即监听mqtt if sta.isconnected(): try: mqtt_c = mqtt.MQTT("mqtt_id", HOST, b'switch', 12) mqtt_c.loop() except: pass # machine.reset() # 否则打开ap模式让用户连接配置 else: ap_list = sta.scan() index_html = get_index_html(ap_list) ap = network.WLAN(network.AP_IF) ap.active(False) ap.active(True) ap.config(essid='智能插座', authmode=0) # 设置webserver addr = socket.getaddrinfo('192.168.4.1', 80)[0][-1]
from time import sleep import socket # for UHF RFID reader - the yellow one... # D-10X # the config and mqtt modules are in a bad place atm :/ import sys sys.path.append('./mqtt/') import mqtt import config import datetime mqttHost = config.getValue("mqtthostname", "mqtt") myHostname = config.getValue("hostname", socket.gethostname()) hostmqtt = mqtt.MQTT(mqttHost, myHostname, "yellow-rfid") ######################################## def readreply(ser): p = ser.read(1) # assert(packet_type == 0xA0) packet_type = int.from_bytes(p, byteorder="big") print(packet_type) if packet_type != 0: print("type == %s" % format(packet_type, '#04x')) l = ser.read(1) length = int.from_bytes(l, byteorder="big") print("length == %u (0x%x)" % (length, length))
def __init__(self): self.mqtt = mqtt.MQTT() self.__init()
from waitress import serve import services import push_notification_service import db import mqtt app = Flask(__name__) db = db.Database() push_notification_service = push_notification_service.PushNotificationService() digitransitAPIService = services.DigitransitAPIService( db, push_notification_service, 'http://api.digitransit.space/routing/v1/routers/hsl/index/graphql') #'http://api.digitransit.fi/routing/v1/routers/hsl/index/graphql') mqtt = mqtt.MQTT(db) @app.route('/') def hello_world(): return 'Hello World!' @app.route('/test') def digitransit_test(): major_minor = [{ "major": 43118, "minor": 56850 }, { "major": 18105, "minor": 59204
import mqtt import settings import time set1 = settings.Settings() messageHandler = mqtt.MQTT("*****@*****.**", "Bepperking!", set1) print(set1.testValue) print("yooooo") messageHandler.subscribe_topic("[email protected]/settings") while True: time.sleep(10) while len(messageHandler.messages) != 0: msg = messageHandler.retrieve_message() msg = msg[1:] msg = msg[:-1] splitted = msg.split(":") if splitted[0] == "MOOD": set1.mood[int(splitted[1])] = splitted[2] print(set1.mood)
from subprocess import call import json import socket # the config and mqtt modules are in a bad place atm :/ import sys sys.path.append('./mqtt/') import config import mqtt GETUID = [0xFF, 0xCA, 0x00, 0x00, 0x00] mqttHost = config.getValue("mqtthostname", "mqtt") myHostname = config.getValue("hostname", socket.gethostname()) hostmqtt = mqtt.MQTT(mqttHost, myHostname, "rfid-nfc") # a simple card observer that prints inserted/removed cards class PrintObserver(CardObserver): """A simple card observer that is notified when cards are inserted/removed from the system and prints the list of cards """ def update(self, observable, actions): (addedcards, removedcards) = actions for card in addedcards: info = toHexString(card.atr).replace(' ', '') print("+Inserted: ", info) connection = card.createConnection()
def __init__(self): self.mqtt = mqtt.MQTT() pass
def main(): mqttObj = mqtt.MQTT() mqttObj.start() topic_active_nodes = "ActiveNodes" topic_node_info = "NodeInfo" topic_updates = "Updates" sqsObj = sqs.SQS() queue = sqsObj.getNodeCommQueue() print("[DEBUG]: Connected to queue") while True: for message in queue.receive_messages(): print ( "Received message {0} from SQS at: {1}".format( message.body, datetime.datetime.now() ) ) if len(message.body) == 0: pass try: js = json.loads( message.body ) # Check if list of active nodes is asked # If it is, then do a get call to our cluster and # get list of active nodes print( "[DEBUG]: Message received ", js ) if ( js['action'].lower() == "active" ): print("[DEBUG]: Active nodes message") r = requests.get( "http://localhost:4001/members" ) # Get JSON response js = json.dumps( r.json() ) mqttObj.publish( topic_active_nodes, js ) print( "deleting message" ) message.delete() # Check if request if for Node info elif ( js['action'].lower() == "info" ): print("[DEBUG]: Info message") r = requests.get( "http://localhost:4001/info" ) js2 = r.json() # Validate node info # If we are the correct node then reply with correct info try: if ( js['node'].lower() == js2['Name'].lower() ): print( "sending node info: ", js ) js2.update( node.getNodeInfo() ) js2 = json.dumps( js2 ) mqttObj.publish( topic_node_info, js2 ) print( "Deleting message" ) message.delete() except KeyError as e: print("[ERROR]: KEY ERROR", js) payload = {"Status":"601", "Msg":"Invalid key"} # mqttObj.publish( topic_updates, json.dumps( payload ) ) message.delete() pass except: print("ERROR in message format") payload = {"Status":"601", "Msg":"Invalid JSON format"} # mqttObj.publish( topic_updates, json.dumps( payload ) ) message.delete() print( "deleting message" ) pass time.sleep(0.01)