Beispiel #1
0
def sendmq(msg):
    UNIQUE_ID = ubinascii.hexlify(machine.unique_id())
    MQTT_BROKER = "192.168.2.68"
    MQTT_PORT = 1883
    MQTT_TOPIC = "iot-2/type/lopy/id/" + "buhardilla" + "/evt/presence1/fmt/json"
    print(MQTT_TOPIC)
    mqtt_client = MQTTClient(UNIQUE_ID, MQTT_BROKER, port=MQTT_PORT)
    mqtt_client.settimeout = settimeout
    mqtt_client.set_callback(t3_publication)
    mqtt_client.connect()
    result = mqtt_client.publish(MQTT_TOPIC, json.dumps(msg))
    mqtt_client.disconnect()
    return result
Beispiel #2
0
if __name__ == "__main__":
    adc0 = machine.ADC(0)  # create ADC object on ADC pin

    rtc = machine.RTC()
    rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP
            )  # create an irq object triggered by a real time clock alarm

    if machine.reset_cause(
    ) == machine.DEEPSLEEP_RESET:  # judge the reset cause
        print('woke from a deepsleep')

    do_connect()

    localclient = MQTTClient("", localmqttHost, port=1883)
    localclient.settimeout = settimeout
    try:
        localclient.connect()
    except Exception as err:
        print("local exception", err)

    remoteclient = MQTTClient(
        "somethingrandom341", mqttHost, user=mqttUsername,
        password=mqttAPIKey)  # port=80 is not working, but 0=1883 is ok
    remoteclient.settimeout = settimeout2
    try:
        remoteclient.connect()
    except Exception as err:
        print("remote exception", err)

    remotetopic = b"channels/" + channelID + b"/publish/" + writeAPIKey
Beispiel #3
0
    elif (msg == b'found'):
        stop_flashing()
    elif (msg.startswith(b'temp')):
        string = msg.decode("utf-8")
        temps = string[5:].split(';')
        temp_range = (float(temps[0]), float(temps[1]))


client = MQTTClient(USER, BROKER, PORT, user=USER, password=PASSWORD)


def settimeout(duration):
    pass


client.settimeout = settimeout
client.set_callback(sub_cup)
client.connect()
client.subscribe(b'/cup')

accelerometer = LIS2HH12()
py = Pytrack()
gps = L76GNSS(py, timeout=30)


def init_socket():
    sigfox = Sigfox(mode=Sigfox.SIGFOX, rcz=Sigfox.RCZ1)
    s = socket.socket(socket.AF_SIGFOX, socket.SOCK_RAW)
    s.setblocking(True)
    s.setsockopt(socket.SOL_SIGFOX, socket.SO_RX, False)
    return s
Beispiel #4
0
from umqtt import MQTTClient

# Initialize MQTT Client
def settimeout(duration): pass


def t3_publication(topic, msg):
	print (topic, ';', msg)
	pycom.rgbled(0xff00)

UNIQUE_ID = machine.unique_id()
MQTT_BROKER = "192.168.2.68"
MQTT_PORT = 1883
MQTT_TOPIC = "iot-2/type/lopy/id/lopy2/evt/evento1/fmt/json"
mqtt_client = MQTTClient(UNIQUE_ID, MQTT_BROKER, port=MQTT_PORT)
mqtt_client.settimeout = settimeout
mqtt_client.set_callback(t3_publication)
mqtt_client.connect()

_LORA_PKG_ACK_FORMAT = "BBB"
_LORA_PKG_FORMAT = "BB%ds"
lora = LoRa(mode=LoRa.LORA, rx_iq=True)
lora_sock = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
lora_sock.setblocking(False)
print("NANO GATEWAY RUNNING!!!")
while (True):
    recv_pkg = lora_sock.recv(512)
    print(recv_pkg)
    time.sleep(5)
    if (len(recv_pkg) > 2):
        recv_pkg_len = recv_pkg[1]
Beispiel #5
0
import socket
import machine, time
import pycom
def settimeout(duration): pass


def t3_publication(topic, msg):
	print (topic, ';', msg)
	pycom.rgbled(0xff00)


UNIQUE_ID = machine.unique_id()
MQTT_BROKER = "test.mosquitto.org"
MQTT_PORT = 1883
mqtt_client = MQTTClient(UNIQUE_ID, MQTT_BROKER, port=MQTT_PORT)
mqtt_client.settimeout = settimeout
mqtt_client.set_callback(t3_publication)
#mqtt_client.connect()

#Publish some data
#print("Sending ON")
#mqtt_client.publish("lopytopic", "ON")
#Subcribe some topic
#mqtt_client.subscribe("lopytopic", qos=1)
#mqtt_client.check_msg()

#Publish on BLUEMIX IOT PLATFORM
mqtt_bluemix = MQTTClient("a:0k1ivs:lopy2", "0k1ivs.messaging.internetofthings.ibmcloud.com", user="******", password="******")
mqtt_bluemix.settimeout = settimeout
mqtt_bluemix.set_callback(t3_publication)
BLUEMIX_TOPIC = "iot-2/type/lopy/id/lopy2/evt/evento1/fmt/json"