Communications

Communication with Algorithms, Arduino and Android

RPi communication with the various subsystems (Algorithms, Arduino, Android) are modulated in their respective classes. The methods are:

  • connect() – Connect to their various subsystems. Algorithms via TCP through WiFi, Arduino via SER_PORT0 or SER_PORT1 if SER_PORT0 fails, Android via RFCOMM through Bluetooth
  • disconnect() – Only for communications with Algorithms and Android, to disconnect them from the RPi
  • readThread() – To read messages from their respective subsystems, processes them to find out the intended destination of those messages. It does the processing by looking at the first character of the message (65 for Arduino, 68 for Android, 80 for Algorithms)
  • write(message) – to send the message to their respective subsystems.
Image Recognition Communication

As the Image Recognition is done on the PC, communication between the RPi and the PC is required to send images over. This is modulated in a sendImg class. The methods of this class are:

  • __init__(self) – Initiases the object, by initialising the camera with the specified resolution and letting the camera warm up using the start_preview function.
  • takePic(self): This function takes a picture from the camera onboard the RPi, serialize it, then sends it to the PC via HTTP POST request. This function is executed when a command for the RPi to take a picture is issued from the Algorithms subsystem (“RP”, ASCII values 82 and 80 respectively).