//*************************************************************** //Program: Mail_Desktop.ino //IDE: Processing //Target Dev: PC/Mac/Linux computer capable of running Processing //Description: Serves as the receiver of serial data from a //wireless MSP430RF2500 and a USB-based MSP430FR5969 LaunchPad //experimenter board. //This sketch listens for a serial string coming in from Node0001 //this is the MSP430 attached to the Mailbox. It parses the string //looking for the light reading from the ambient light sensor. //If that voltage reading exceed the thrshold voltage of 0.5V then //it send a keyword string "MAIL" to the LaunchPad device. //The LaunchPad in turn handles activiating a servo and LED. //*************************************************************** //Import needed libraries import processing.serial.*; //Declare and initialize variables int lf = 10; float voltage = 0.0; String myString = null; String voltString = null; String deviceID = null; String Node1 = "0001"; float thresholdVal = 0.5; Serial myInPort; Serial myOutPort; PFont f; //*************************************************************** //Function: setup //Description: Intializes the hardware such as the serial ports //and establishes parameters for the screen that is displayed //on the computer. //*************************************************************** void setup() { //Display all attached COM ports println(Serial.list()); //Declare input port from MSP430RF2500 //Declare string to store the serial stream, initialize blank. myInPort = new Serial(this, Serial.list()[2], 9600); myInPort.clear(); myString = myInPort.readStringUntil(lf); myString = null; //Declare the output serial port to the LaunchPad myOutPort = new Serial(this, Serial.list()[0], 9600); myOutPort.clear(); //Declare screen parameters and initialize size(500, 100); f = createFont("Arial", 16, true); background(255); textFont(f, 16); fill(0); text("Awaiting Delivery.", 10, 60); //text(voltString+"V", 10, 60); //debug statement to see raw voltage reading println(myString); } //*************************************************************** //Function: draw //Description: This is the main loop that constantly runs. //Procedure is: // - Read serial stream from RF2500 // -If it is from device connected to mailbox, parse string // -If the voltage level contained in the string, exceeds 0.5V then // -Send keyword "MAIL" over serial port to the LaunchPad // -Otherwise ignore and continue to listen //*************************************************************** void draw() { while (myInPort.available () > 0) { //If string avialble to read, read into myString myString = myInPort.readStringUntil(lf); if (myString != null) { //println(myString); //debug statement to see raw string } } //Parse out the node indentifier, we only want to handle the Mailbox MSP430 //Parse out the voltage reading from the ambient light sensor voltString = myString.substring(30, 33); deviceID = myString.substring(5, 9); //If this is the MSP430 connected to the Mailbox, proceed if (deviceID.equals(Node1) == true ) { voltage = float(voltString); //convert votlage from string to float if (voltage > thresholdVal) { //If voltage exceeds threshold myOutPort.write("Mail"); //Send message to LaunchPad myOutPort.write("\n"); background(255); textFont(f, 16); fill(0); text("Delivery In Progress!", 10, 60); //Give onscreen confirmation to user println(myString); } else { //Else send a NEGATIVE message to LaunchPad myOutPort.write("NoMail"); myOutPort.write("\n"); background(255); textFont(f, 16); fill(0); text("Awaiting Delivery.", 10, 60); println(myString); } } }