I'm beginner in integrating TTN / CayenneLPP

Here I am again. I have an application sending temperature, pressure and digital signal (NO / NC). However, I tried to add a signal from a cayenneLPP format ultrasonic sensor but it didn’t work. How can I solve this problem, is it related to the data size or socket?

The code below is the configuration of LoraWAN and cayenne LPP along with shipping packages.

# remove all the channels
for channel in range(0, 72):
lora.remove_channel(channel)

# set all channels to the same frequency (must be before sending the OTAA join request)
for channel in range(0, 72):
    lora.add_channel(channel, frequency=config.LORA_FREQUENCY, dr_min=0, dr_max=3)

# join a network using ABP (Activation By Personalization)
lora.join(activation=LoRa.ABP, auth=(dev_addr, nwk_swkey, app_swkey))

# create a LoRa socket
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)

# set the LoRaWAN data rate
s.setsockopt(socket.SOL_LORA, socket.SO_DR, config.LORA_NODE_DR)

# make the socket non-blocking
s.setblocking(False)

# creating Cayenne LPP packet
lpp = cayenneLPP.CayenneLPP(size = 100, sock = s)

while True:
    # Receiving fifteen temperature and pressure readings.
    bmet = []   # Lista com as temperaturas lidas com o BME280
    bmep = []   # Lista com as umiadades lidas com o BME280
    numreadings = 15
    samples_temperature = [0.0]*numreadings; mean_temperature = 0.0
    samples_pressure = [0.0]*numreadings; mean_pressure = 0.0
    samples_humidity = [0.0]*numreadings; mean_humidity = 0.0
    for i in range (numreadings):
        samples_temperature[i], samples_pressure[i], samples_humidity[i] = bme.values
    mean_temperature = sum(samples_temperature)/len(samples_temperature)
    mean_pressure = sum(samples_pressure)/len(samples_pressure)
    t = mean_temperature
    p = mean_pressure/100 # Pa -> hectoPa
    bmet.append(t)
    bmep.append(p)
    print("Temperatura:",t, "C e Pressao: ",p, "hPa")

    # Receiving the average distance of the function.
    distance = distance_median()
    print("Distance:  ", distance)

    # Packaging the data in cayenneLPP format
    lpp.add_digital_input(distance, channel = 116)
    lpp.send(reset_payload = True)

    lpp.add_temperature(bmet[0])
    lpp.add_barometric_pressure(bmep[0])
    lpp.send(reset_payload = True)

    if pm1.value() == False and pm2.value() == False and pm3.value() == False and pm4.value() ==     False:
        print("Nivel atingiu 4 metros!")
        lpp.add_digital_input(True)
        lpp.add_digital_input(True, channel = 112)
        lpp.send(reset_payload = True)

        lpp.add_digital_input(True, channel = 113)
        lpp.add_digital_input(True, channel = 114)
        lpp.send(reset_payload = True)

    if pm1.value() == False and pm2.value() == False and pm3.value() == False and pm4.value() ==     True:
        print("Nivel atingiu 3 metros!")
        lpp.add_digital_input(True)
        lpp.add_digital_input(True, channel = 112)
        lpp.send(reset_payload = True)

        lpp.add_digital_input(True, channel = 113)
        lpp.add_digital_input(False, channel = 114)
        lpp.send(reset_payload = True)

    if pm1.value() == False and pm2.value() == False and pm3.value() == True and pm4.value() ==     True:
        print("Nivel atingiu 2 metros!")
        lpp.add_digital_input(True)
        lpp.add_digital_input(True, channel = 112)
        lpp.send(reset_payload = True)

        lpp.add_digital_input(False, channel = 113)
        lpp.add_digital_input(False, channel = 114)
        lpp.send(reset_payload = True)

    if pm1.value() == False and pm2.value() == True and pm3.value() == True and pm4.value() ==     True:
        print("Nivel atingiu 1 metros!")
        lpp.add_digital_input(True)
        lpp.add_digital_input(False, channel = 112)
        lpp.send(reset_payload = True)

        lpp.add_digital_input(False, channel = 113)
        lpp.add_digital_input(False, channel = 114)
        lpp.send(reset_payload = True)

    if pm1.value() == True and pm2.value() == True and pm3.value() == True and pm4.value() ==     True:
        print("Nivel abaixo do normal!")
        lpp.add_digital_input(False)
        lpp.add_digital_input(False, channel = 112)
        lpp.send(reset_payload = True)

        lpp.add_digital_input(False, channel = 113)
        lpp.add_digital_input(False, channel = 114)
        lpp.send(reset_payload = True)

    time.sleep(60)

Img ERROR:
cayenne

not sure about this issue, but found this https://forum.pycom.io/topic/2590/oserror-errno-11-eagain/2

I think I solved the problem, I put a delay between sending each variable to have no message conflicts and it worked perfectly, I just don’t know if it’s the right way hahaha. by the way, thank you very much!!

2 Likes