Last active
August 14, 2019 21:11
-
-
Save jotathebest/e624c62d1bc4dc7d27627f2f63ed87c7 to your computer and use it in GitHub Desktop.
Script for sending data to Ubidots using UDP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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