I am using the book Android Development from Prof Dogan Ibrahim ,This example of using a socket on the RPI to send the temperature read from the sense HAT to a Andriod device,
my Andrioud device app is running but when running the python script I get the following error
that sock.sendto(str(T),(UDP_IP,UDP_PORT)) needs a byte type not string ,Please help me how do I send the
temperature over the socket
Code: Select all
#=================================================================
# get Temperature and send to phone(Android)
# SenseHAT + RPI 3B
#=================================================================
import socket #import Network Sockets
import time # import time module
from sense_hat import SenseHat #import Sensehat library
sense = SenseHat() # create instance of Sense HAT
#---------------------------------------------------------------
# create socket and initialize network
UDP_PORT = 2000
UDP_IP = "192.168.1.160" #Mobile IP adress
sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
#===============================================================
#Run App
while True:
T = sense.get_temperature() #read the temperature sensor
T = round(T,1) #round off the results
sock.sendto(str(T),(UDP_IP,UDP_PORT)) # send temperature to Android device
time.sleep(2) # wait 2 seconds