Send data to ubidot via UDP


#1

Hi,
Greetings. I was trying to send my data via UDP to Ubidots but my code is generating a device in Ubidot but was not receiving any data.
I am using a Raspberry Pi 3with a cellular IOT shield and code is in python3.
Can anyone please help me.


#2

Greetings, this code may serve you as reference for sending data using UDP:

import socket
import time
import json
import requests
import os

# UBIDOTS PARAMETERS
SERVER = "industrial.api.ubidots.com"
PORT = 9012
BUFFER_SIZE = 1024
TOKEN = ""

def send_packet(token):
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 
        s.connect_ex((SERVER, PORT))
        s.settimeout(10)
        message = "test/1|POST|{}|".format(token)
        message = "{}uptime-monitor:uptime-monitor=>udp:1|end".format(message)
        s.send(message.encode())
        data = s.recv(BUFFER_SIZE)
        print(f'server response: {data}')
        s.close()
    except Exception as e:
        #timeout
        print(f'there was an error sending data, details:\n{e}')

All the best


#3

Hi,

my VPN server is receiving data but while I am trying to send data to ubidots it is just generating a device.But not receiving any data .Can any one help me to solve the problem?