Skip to content

Instantly share code, notes, and snippets.

@jotathebest
Last active August 14, 2019 21:11
Show Gist options
  • Save jotathebest/e624c62d1bc4dc7d27627f2f63ed87c7 to your computer and use it in GitHub Desktop.
Save jotathebest/e624c62d1bc4dc7d27627f2f63ed87c7 to your computer and use it in GitHub Desktop.
Script for sending data to Ubidots 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)
response = data.decode()
print(f'server response: {response}')
if response != 'OK':
return False
s.close()
return True
except Exception as e:
print(f'there was an error, details: {e}')
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment