Problem with Arduino + SIM908 (GPRS module) | ThingSpeak API | Forum

Avatar

Please consider registering
Guest

Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

Register Lost password?
sp_Feed sp_TopicIcon
Problem with Arduino + SIM908 (GPRS module)
Avatar
Aitorto8
New Member
Forum Posts: 2
sp_UserOfflineSmall Offline
1
July 4, 2017 - 5:20 pm
sp_Permalink sp_Print

Hi, I want to upload data to Thingspeak using the SIM908 module, but I don't get any answer in my Thingspeak channel.

I'm new with this and if you could help me it would be great. Here is the code:

 

int8_t answer;
int onModulePin= 2;

char aux_str[50];

 

float pressure= 100;
String humidity="1";

String str;

void setup(){

pinMode(onModulePin, OUTPUT);
Serial.begin(115200);

Serial.println("Starting...");
power_on();

delay(3000);

// sets the PIN code
sendATcommand2("AT+CPIN=3765", "OK", "ERROR", 2000);

delay(3000);

while (sendATcommand2("AT+CREG?", "+CREG: 0,1", "+CREG: 0,5", 1000)==0);

}
void loop(){

 

humidity = "70";
pressure = 100;

str="GET http://api.thingspeak.com/update?api_key=TPGL5UMZGNYO857K&field1=" + String(pressure);

bidali();

delay (20000);
}

void bidali (){

char message_TCP [300];
str.toCharArray(message_TCP, 300); // converting TCP_message to char inorder for it to pass through AT command

if(sendATcommand2("AT+CIPMUX=0","OK","ERROR",1000)==1)
{
while(sendATcommand2("AT+CIPSTATUS","INITIAL","",500)==0);
delay(5000);

if(sendATcommand2("AT+CSTT=\"gprs-service.com\",\"\",\"\"","OK","ERROR",30000)==1)
{
while(sendATcommand2("AT+CIPSTATUS","START","",500)==0);
delay(5000);

if(sendATcommand2("AT+CIICR","OK","ERROR",30000)==1)
{
while(sendATcommand2("AT+CIPSTATUS","GPRSACT","",500)==0);
delay(5000);

if(sendATcommand2("AT+CIFSR",".","ERROR",10000)==1)
{
while(sendATcommand2("AT+CIPSTATUS","IP STATUS","",500)==0);
delay(5000);
Serial.println("Openning TCP");

if(sendATcommand2("AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",\"80\"","CONNECT OK", "CONNECT FAIL", 30000)==1)
{
Serial.println("Konektatua");

sprintf(aux_str,"AT+CIPSEND=%d", strlen(message_TCP));
if(sendATcommand2(aux_str,">","ERROR",10000)==1)
{
sendATcommand2(message_TCP,"","ERROR",20000);
Serial.println("Mensaje mandado!");
}
sendATcommand2("AT+CIPCLOSE","CLOSE OK","ERROR",10000);
}
else
{
Serial.println("Errorea konexioa irekitzen");
}
}
else
{
Serial.println("Errorea IP helbidea lortzen");
}
}
else
{
Serial.println("Errorea hari gabeko konexioa irekitzen");
}
}
else
{
Serial.println("Errorea APN-a konfigurazioarekin");
}
}
else
{
Serial.println("Errorea konexioa ezartzen");
}
sendATcommand2("AT+CIPSHUT","OK","ERROR",10000);

delay (4000);

}

void power_on(){

uint8_t answer=0;

// checks if the module is started
answer = sendATcommand2("AT", "OK", "OK", 2000);
if (answer == 0)
{
// power on pulse
digitalWrite(onModulePin,HIGH);
delay(3000);
digitalWrite(onModulePin,LOW);

// waits for an answer from the module
while(answer == 0){
// Send AT every two seconds and wait for the answer
answer = sendATcommand2("AT", "OK", "OK", 2000);
}
}
}

int8_t sendATcommand2(char* ATcommand, char* expected_answer1,
char* expected_answer2, unsigned int timeout)
{

uint8_t x=0, answer=0;
char response[100];
unsigned long previous;

memset(response, '\0', 100); // Initialize the string

delay(100);

while( Serial.available() > 0) Serial.read(); // Clean the input buffer

Serial.println(ATcommand); // Send the AT command

 

x = 0;
previous = millis();

// this loop waits for the answer
do{

if(Serial.available() != 0){
response[x] = Serial.read();
x++;
// check if the desired answer is in the response of the module
if (strstr(response, expected_answer1) != NULL)
{
answer = 1;
}
else if(strstr(response, expected_answer2) !=NULL)
{
answer=2;
}
}

}
// Waits for the asnwer with time out
while((answer == 0) && ((millis() - previous) < timeout));

return answer;
}

What can be wrong? Thank you!

Avatar
cstapels

Gold
Forum Posts: 54
sp_UserOfflineSmall Offline
2
July 12, 2017 - 8:27 am
sp_Permalink sp_Print sp_EditHistory

What response codes are you getting when you post with this software?  Have you tried the post in a browser or POSTSMAN?  The formatting of your HTTP request looks correct.

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
24 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 250

Vinod: 140

piajola: 73

vespapierre: 63

Adarsh_Murthy: 59

cstapels: 54

Newest Members:

Duck

darsana123

decx

ginkgo88

angy1551

wayari

Forum Stats:

Groups: 4

Forums: 17

Topics: 1239

Posts: 4308

 

Member Stats:

Guest Posters: 1

Members: 5537

Moderators: 0

Admins: 2

Administrators: Hans, lee