Arduino and Konekt


#1

Thought I’d share my experiences and create a discussion for this that may be using Konekt and Arduino.

I have my Arduno/Seeed2.0/Konekt setup running and firing off a web service and receiving data back into Arduino. Cool stuff!

Unfortunately, the 64 byte max serial buffer size on the Arduino posses a significant limitation on M2M data passing since the web service header data returned fills too much of the return buffer. Figuring I will be better off skipping the web service and just making a simple http url call with name pairs and then returning simple HTML or XML up to the 64 byte max.

Any other ideas on how the best get data back into the Arduino?


#2

Hi manbat,

May I inquire about this web service? Could you also copy/paste the arduino sketch you are using to read the data? You should be able to receive more than 64 bytes at a time, so long as you are doing continuous serial reads on the buffer, at a rate that is faster than it’s being filled.

Best,

-Pat


#3

Nothing special about the web service. it’s just a test that returns xml. Code is a slight modification of the sketch posted in the blog that loads the returned data into a string. I have tried numerous approaches to load the string while Serial.available() from one character at a time to Serial.readStringUntil() but never seem to get it all. Could it be related to the delay in receiving and then readStringUntil() wont get it all?

#include <SoftwareSerial.h>
 
SoftwareSerial mySerial(7, 8);
 


void setup()
{
  mySerial.begin(19200); // the GPRS baud rate
  Serial.begin(19200); // the GPRS baud rate
  delay(500);
}
 
void loop()
{
  // Input 'h' to run the test HTTP program
  if (Serial.available())
      
    switch(Serial.read())
    {
      case 'h':
        SubmitHttpRequest("h");
        break;
      case 'r':
        SubmitHttpRequest("r");
      break;
    }
  if (mySerial.available())
    Serial.write(mySerial.read());
}
 
// SubmitHttpRequest()
//
// Note: the time of the delays are very important
void SubmitHttpRequest(String serialVal)
{
  if(serialVal != "r")
  {
  // Query signal strength of device
  mySerial.println("AT+CSQ");
  delay(100);
   
  ShowSerialData();
 
  // Check the status of Packet service attach. '0' implies device is not attached and '1' implies device is attached.
  mySerial.println("AT+CGATT?");
  delay(100);

  ShowSerialData();
 
  // Set the SAPBR, the connection type is using gprs
  mySerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
  delay(1000);

  ShowSerialData();
 
  // Set the APN
  mySerial.println("AT+SAPBR=3,1,\"APN\",\"apn.konekt.io\"");
  delay(4000);

  ShowSerialData();
 
  // Set the SAPBR, for detail you can refer to the AT command manual
  mySerial.println("AT+SAPBR=1,1");
  delay(2000);
  }
 
  ShowSerialData();
 
  // Init the HTTP request
  mySerial.println("AT+HTTPINIT");
 
  delay(2000);
 
  ShowSerialData();
  
  
 
  // Set HTTP params, the second param is the website to request
  mySerial.println("AT+HTTPPARA=\"URL\",\"gyroscopeit.com/dashboard/RPiTest.cfc?wdsl&method=testRPi&validate=1\"");
  delay(1000);
 
  ShowSerialData();
 
  //Set the context ID
  mySerial.println("AT+HTTPPARA=\"CID\",1");
  delay(1000);

  ShowSerialData();
 
  // Submit the request
  mySerial.println("AT+HTTPACTION=0");
  // The delay is very important, the delay time is base on the
  // return time from the website, if the return data is very
  // large, the time required might be longer.
  delay(10000);
  
  ShowSerialData();
 
  // Read the data from the accessed website
  mySerial.println("AT+HTTPREAD");
  delay(10000);
  
  //ShowSerialData();
  ShowDataReturn();
 
  // Close the HTTP connection and display the data
  mySerial.println(" ");
  mySerial.println("AT+HTTPTERM");
  delay(100);
  
  ShowSerialData();
}

 /*******************************************************************************************************/
void ShowDataReturn()

{
 
  String data2;
  
  
  if(mySerial.available() > 0)
  {
     data2 = mySerial.readStringUntil('\n');
   }
  
  Serial.println(data2.length());
  Serial.println(data2);

} 
 
 

// ShowSerialData()
// This is to show the data from gprs shield, to help
// see how the gprs shield submits an http request.
void ShowSerialData()
{
  
  while(mySerial.available()!=0)
    Serial.write(mySerial.read());
   
  
}

#4

Some progress. Looks like when I eliminate the delay after the HTTPREAD in the example code all the data returned from the web service call is displayed. Your right about the serial buffer, now I understand that it holds 64 bytes at a time and 64 bytes is not the max size for serial data.


#5