1

I have a Django web application hosted on a Heroku server. Currently I am using the free package for hosting. I want to send data from an Arduino using a SIM900L GPRS module to the web application. I want to know if it is possible. I have searched for a solution but couldn't find a proper guide or example for it. My web application accepts get requests and updates values in the database when url is entered. However if the Arduino sends data using the same url I get the following error:

AT+CIPSTART="TipCP","https://.herokuapp.com",80 ERROR

Any tested example or suggestions about what I am doing wrong or what I should be doing instead?

 void gprs(float *value1, float *value2, float *value3, float *AFR, float *value5, float *value6)
{
 String APN = "";
 String UNAME = "";
 String PWD = "";
 char fid[] = "";
 char nid[] = "";
 char s_ip[] = "https://<appname>.herokuapp.com";
 char apikey[] = "";
 wdt_reset();
 digitalWrite(A4, HIGH);
 Serial.println(F("GPRS-1 Function"));
 delay(5000);
 wdt_reset();
 delay(5000);
 wdt_reset();
 char buffer1[10];
 uint8_t GSMTries = 0;
 String res;
 //wdt_reset();
 // the below code establishes connection and if not successful
 // tries three times in total
 do {
 sendData(F("AT\r\n"), 1000, DEBUG);
 sendData(F("AT+CIPSHUT\r\n"), 2000, DEBUG);
 sendData(F("AT+CIPMUX=0\r\n"), 2000, DEBUG);
 sendData(F("AT+CSQ\r\n"), 2000, DEBUG);
 sendData("AT+CSTT= \"" + APN + "\", \"" + UNAME + "\", \"" + PWD + "\"\r\n", 2000, DEBUG);
 sendData(F("AT+CIICR\r\n"), 2000, DEBUG);
 sendData(F("AT+CIFSR\r\n"), 2000, DEBUG);
 sendData(F("AT+CSQ\r\n"), 2000, DEBUG);
 String scnt = "AT+CIPSTART=\"TipCP\",\"" ;
 scnt += s_ip ;
 scnt += "\",80\r\n" ;
 res = sendData(scnt, 10000, DEBUG);
 GSMTries++;
 wdt_reset();
 } while (((res.indexOf("ERROR") != -1) || (res.indexOf("CONNECT") == -1)) && (GSMTries < 3));
 /*
 if(res.indexOf("ERROR") != -1){
 delay(200);
 sendData(scnt, 10000, DEBUG);
 }
 */
 String api = "GET /value?apkey=" ;
 api += apikey;
 api += "&&fid=";
 api += fid;
 api += "&&nid=";
 api += nid;
 Serial.println(F("API......."));
 Serial.flush();
 Serial.println(F("here-1"));
 String Data1 = "";
 //wdt_reset();
 //Co ordinator data is compiled along with html commands
 //and sent through GPRS
 String sensor = dtostrf(*value1, 4, 2, buffer1);
 Data1.concat(api);
 Data1.concat(F("&field1="));
 Data1.concat(sensor);
 sensor = dtostrf(*value2, 4, 2, buffer1);
 Data1.concat(F("&field2="));
 Data1.concat(sensor);
 sensor = dtostrf(*value3, 4, 2, buffer1);
 Data1.concat(F("&field3="));
 Data1.concat(sensor);
 sensor = dtostrf(*AFR, 4, 2, buffer1);
 Data1.concat(F("&field4="));
 Data1.concat(sensor);
 sensor = dtostrf(*value4, 4, 2, buffer1);
 Data1.concat(F("&field5="));
 Data1.concat(sensor);
 sensor = dtostrf(*value6, 4, 2, buffer1);
 Data1.concat(F("&field6="));
 Data1.concat(sensor);
 Data1.concat(F("\r\n"));
 delay(1000);
 String cipSend = "AT+CIPSEND=";
 cipSend.concat(Data1.length());
 cipSend.concat("\r\n");
 sendData(cipSend, 8000, DEBUG);
 sendData(Data1, 8000, DEBUG);
 sendData(F("AT+CIPCLOSE\r\n"), 5000, DEBUG);
 digitalWrite(A4, LOW);
 wdt_reset();
}

The above is a part of code used in arduino to upload data to website. This code was being used before to upload data to thingspeak through its IP address and worked fine.

asked Sep 8, 2017 at 4:17
1
  • 1
    Why is this tagged as python? Commented Sep 8, 2017 at 14:56

1 Answer 1

1

There's a number of errors in your program regarding your understanding of basic networking:

Let's start with this bit:

String scnt = "AT+CIPSTART=\"TipCP\",\"" ;
scnt += s_ip ;
scnt += "\",80\r\n" ;

That constructs a string:

AT+CIPSTART="TipCP","https://<appname>.herokuapp.com",80

and sends it to the modem. Now:

  1. There is no such protocol as "TipCP" - I think you meant "TCP"
  2. You need to provide an FQDN (Fully Qualified Domain Name), not a URL. FQDNs don't start with "https://". I think you meant to use "foobar.herokuapp.com" where "foobar" is the name of your application.

You then go on to form a GET request and send it.

Now: the URL you used instead of an FQDN starts with https:// - that tells me you want to be using SSL for your communications. I don't know if that is required for Heroku or not, but if it is then you cannot use AT+CIPSTART with it unless you feel like trying to implement the entirety of SSL in your program. Also you would be connecting to port 443 not port 80.

Assuming you don't need SSL fixing your protocol and FQDN may be enough. However using the AT+HTTP... commands instead of manual manipulation of a raw TCP socket may be an easier option.

If you do need SSL (and it is advisable that you do if you can) then you will have to use the SIM900's AT+HTTPS... command set (detailed here).

answered Sep 8, 2017 at 10:52

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.