problem with sim900 gprs


hi

today trying connect sim900 v1.4 gprs shield arduino uno working fine turned off tried opening again stays on while again , when put on fxt stays on until close can fix

thanks

the code:

/*note: code demo how using gprs shield send sms message, dial voice call ,
 send http request website, upload data pachube.com tcp connection,

 the microcontrollers digital pin 7 , hence allow unhindered
 communication gprs shield using softserial library.
 ide: arduino 1.0 or later
 replace following items in code:
 1.phone number, don't forget add country code
 2.replace access point name
 3. replace pachube api key personal ones assigned
 to account @ cosm.com
 */


#include <softwareserial.h>
#include <string.h>

softwareserial myserial(7, 8);

void setup()
{
 myserial.begin(19200);               // gprs baud rate  
 serial.begin(19200);    // gprs baud rate
 delay(500);
}

void loop()
{
 //after start program, can using terminal connect serial of gprs shield,
 //if input 't' in terminal, program execute sendtextmessage(), show how send sms message,
 //if input 'd' in terminal, execute dialvoicecall(), etc.

 if (serial.available())
   switch(serial.read())
  {
    case 't':
      sendtextmessage();
      break;
    case 'd':
      dialvoicecall();
      break;
    case 'h':
      submithttprequest();
      break;
    case 's':
      send2pachube();
      break;
  }
 if (myserial.available())
   serial.write(myserial.read());
}

///sendtextmessage()
///this function send sms message
void sendtextmessage()
{
 myserial.print("at+cmgf=1\r");    //because want send sms in text mode
 delay(100);
 myserial.println("at + cmgs = \"+973********\"");//send sms message, careful need add country code before cellphone number
 delay(100);
 myserial.println("a test message!");//the content of message
 delay(100);
 myserial.println((char)26);//the ascii code of ctrl+z 26
 delay(100);
 myserial.println();
}

///dialvoicecall
///this function dial voice call
void dialvoicecall()
{
 myserial.println("atd + +973*******;");//dial number
 delay(100);
 myserial.println();
}

///submithttprequest()
///this function submit http request
///attention:the time of delay important, must set enough
void submithttprequest()
{
 myserial.println("at+csq");
 delay(100);

 showserialdata();// code show data gprs shield, in order see process of how gprs shield submit http request, , following purpose too.

 myserial.println("at+cgatt?");
 delay(100);

 showserialdata();

 myserial.println("at+sapbr=3,1,\"contype\",\"gprs\"");//setting sapbr, connection type using gprs
 delay(1000);

 showserialdata();

 myserial.println("at+sapbr=3,1,\"viva.bh\",\"cmnet\"");//setting apn, second need fill in local apn server
 delay(4000);

 showserialdata();

 myserial.println("at+sapbr=1,1");//setting sapbr, detail can refer @ command mamual
 delay(2000);

 showserialdata();

 myserial.println("at+httpinit"); //init http request

 delay(2000);
 showserialdata();

 myserial.println("at+httppara=\"url\",\"www.google.com\"");// setting httppara, second parameter website want access
 delay(1000);

 showserialdata();

 myserial.println("at+httpaction=0");//submit request
 delay(10000);//the delay important, delay time base on return website, if return datas large, time required longer.
 //while(!myserial.available());

 showserialdata();

 myserial.println("at+httpread");// read data website access
 delay(300);

 showserialdata();

 myserial.println("");
 delay(100);
}

///send2pachube()///
///this function send sensor data pachube, can see new value in pachube after execute function///
void send2pachube()
{
 myserial.println("at+cgatt?");
 delay(1000);

 showserialdata();

 myserial.println("at+cstt=\"cmnet\"");//start task , setting apn,
 delay(1000);

 showserialdata();

 myserial.println("at+ciicr");//bring wireless connection
 delay(3000);

 showserialdata();

 myserial.println("at+cifsr");//get local ip adress
 delay(2000);

 showserialdata();

 myserial.println("at+cipsprt=0");
 delay(3000);

 showserialdata();

 myserial.println("at+cipstart=\"tcp\",\"api.cosm.com\",\"8081\"");//start connection
 delay(2000);

 showserialdata();

 myserial.println("at+cipsend");//begin send data remote server
 delay(4000);
 showserialdata();
 string humidity = "1031";//these 4 line code imitate real sensor data, because demo did't add other sensor, using 4 string variable replace.
 string moisture = "1242";//you can replace these 4 variable real sensor data in project
 string temperature = "30";//
 string barometer = "60.56";//
 myserial.print("{\"method\": \"put\",\"resource\": \"/feeds/42742/\",\"params\"");//here feed apply pachube
 delay(500);
 showserialdata();
 myserial.print(": {},\"headers\": {\"x-pachubeapikey\":");//in here, should replace pachubeapikey
 delay(500);
 showserialdata();
 myserial.print(" \"_cxwr5le8qw4a296o-cdwouvfddfer5pgmarigpsio0");//pachubeapikey
 delay(500);
 showserialdata();
 myserial.print("jeb9ojk-w6vej56j9itasliac-hgbqjxexuved95yc8bttxc");//pachubeapikey
 delay(500);
 showserialdata();
 myserial.print("z7_sezqlvjecomnbexuva45t6fl8axocunssqs\"},\"body\":");
 delay(500);
 showserialdata();
 myserial.print(" {\"version\": \"1.0.0\",\"datastreams\": ");
 delay(500);
 showserialdata();
 myserial.println("[{\"id\": \"01\",\"current_value\": \"" + barometer + "\"},");
 delay(500);
 showserialdata();
 myserial.println("{\"id\": \"02\",\"current_value\": \"" + humidity + "\"},");
 delay(500);
 showserialdata();
 myserial.println("{\"id\": \"03\",\"current_value\": \"" + moisture + "\"},");
 delay(500);
 showserialdata();
 myserial.println("{\"id\": \"04\",\"current_value\": \"" + temperature + "\"}]},\"token\": \"lee\"}");


 delay(500);
 showserialdata();

 myserial.println((char)26);//sending
 delay(5000);//waitting reply, important! time base on condition of internet
 myserial.println();

 showserialdata();

 myserial.println("at+cipclose");//close connection
 delay(100);
 showserialdata();
}

void showserialdata()
{
 while(myserial.available()!=0)
   serial.write(myserial.read());
}

how powered ?
usb not enough, need external power supply, able deliver 2a when needed .
(when tries connect network etc... , sim900 may need 2a . )


Arduino Forum > Using Arduino > General Electronics > problem with sim900 gprs


arduino

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support