Storing incoming data from the serial port...having a tough time
in
Core Library Questions
•
1 year ago
I am using an Arduino with a cellular module as a "modem" for my computer. I send it data via txt message.
The code successfully recognizes incoming characters and takes action, however I need it to store the text message "text" in an array that I can use. The code does everything correct except generate the array. I have included the code, I have a hunch that it's something to do with either where/how the storeData function is called OR the for loop I use to store data. Please take a look! Thanks so much
- import processing.serial.*;
- import processing.net.*;
- //Serial Variables
- Serial myPort; // the serial port you're using
- String portnum; // name of the serial port
- String inString = ""; // the string coming in from the serial port
- int inByte;
- //SMS Variables
- int SMS_counter = 0;
- String stat = "";
- String GBstat = "";
- char[] SMS_data = new char[10];
- //HTTP Variables
- Client client;
- int sent_num = 0;
- boolean requestInProgress = false;
- String responseString = "";
- String requestString = "";
- String callStat= "";
- void setup()
- {
- size(600, 800);
- PFont myFont = createFont(PFont.list()[2], 14);
- textFont(myFont);
- println(Serial.list());
- portnum = Serial.list()[1];
- myPort = new Serial(this, portnum, 9600);
- }
- void draw()
- {
- background(0);
- text("SMS Counter:\n" + SMS_counter, 10,20);
- text("Status:\n" + GBstat, 10, 60);
- text("HTTP Call Status:\n" + callStat, 10,100);
- text("# HTTP Requests Sent:\n" + sent_num, 10,140);
- text("Data Received:\n" + SMS_data, 10,180);
- text("Received:\n" + inString, 10, 220);
- storeData();
- makeHTTPCall();
- }
- void serialEvent(Serial myPort)
- {
- int inByte = myPort.read();
- inString += char(inByte);
- if(char(inByte) == '?')
- {
- SMS_counter = 1;
- }
- if(SMS_counter == 1)
- {
- myPort.write("AT+CMGD=1,4");
- myPort.write(0x0D);
- SMS_counter = 0;
- }
- if(char(inByte) == 'g')
- {
- stat = "Good";
- GBstat = "Good";
- }
- if(char(inByte) != 'g' && char(inByte) == 'b')
- {
- stat = "Bad";
- GBstat = "Bad";
- }
- }
- void makeHTTPCall()
- {
- if (stat == "Good" || stat == "Bad")
- {
- callStat = "Entered HTTP Loop";
- println("Entered HTTP Loop");
- callStat = "";
- if (requestInProgress == false)
- {
- client = new Client(this, "www.example.com", 80);
- requestString = "example"; //+stat;
- println(requestString);
- client.write("GET " + requestString + " HTTP/1.0\n");
- client.write("HOST: example.com\n\n");
- requestInProgress = true;
- stat = "Null";
- callStat = "HTTP Request Sent";
- sent_num = sent_num + 1;
- }
- }
- requestInProgress = false;
- }
- void storeData()
- {
- if(char(inByte) == '?')
- {
- for( int i=0; i<10; i = i+1)
- {
- SMS_data[i] = char(inByte);
- }
- }
- }
1