GSM_SIM900

Odpovědět
Jirka
Příspěvky: 55
Registrován: 18 lis 2015, 12:06

GSM_SIM900

Příspěvek od Jirka »

Zdravím,
zabýval se někdo víc GSM modulem se SIM900 ? Jde mi o to, že v popisu se píše, "pin 9 je ekvivalent tlačítka POWER".
Ale s tím se mi jaksi nedaří jej zapnout.
hubacekp
Příspěvky: 259
Registrován: 24 úno 2013, 13:40

Re: GSM_SIM900

Příspěvek od hubacekp »

Už je to skoro rok, ale myslím, že se musí nějakou dobu držet pin 9 na HIGH
a potom počkat, než ten SIM shield naběhne a chytí GSM signál.
Bez zachycení signálu to neodpovídá OK a nejde dokončit inicializace a samozřejmě ani nic poslat :-)

Jestli se ti to povede rozchodit, dej vědět.

Jak zapnout:

Kód: Vybrat vše

void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
  digitalWrite(9, HIGH);
  delay(1000);
  digitalWrite(9, LOW);
  delay(5000);
}
celý kód i s tutorialy, odkud jsem čerpal:

Kód: Vybrat vše

/* Circuit:
 * Arduino board
 * GSM shield SIM900 + external power
 * SIM card that can send SMS

 Tutorials:
 http://tronixstuff.com/2014/01/08/tutorial-arduino-and-sim900-gsm-modules/
 https://vsblogs.wordpress.com/2013/11/28/tcp-connection-over-gprs-using-sim900-and-at-commands/

*/


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

String temp = "";
unsigned int lastTest = 0;
int testNumber = 0;
int testPeriod = 2000;
int testAnswer = 0;

void setup()
{
  Serial.begin(9600);
  Serial.println("SIM900.begin");
  SIM900.begin(19200);
  SIM900power();
  Serial.println("wait 15s");
  delay(15000);  // give time to log on to network.
  Serial.println("Setup End");
}

void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
  digitalWrite(9, HIGH);
  delay(1000);
  digitalWrite(9, LOW);
  delay(5000);
}

void GPRStest(String _str)
{
  Serial.print(">");
  Serial.println(testNumber);
  Serial.print(">");
  Serial.print(_str);
  SIM900.print(_str);                                                        // AT command to send SMS message
  testNumber++;
  testAnswer = 0;
  lastTest = millis();
  delay(200);
}

void GPRStestN()
{
  SIM900.println((char)26);                       // End AT command with a ^Z, ASCII code 26 // turn off module
  delay(1000);
  SIM900power();                                   // turn off module
}

void loop()
{
  if (millis() - lastTest > testPeriod && testNumber == 0) {
    GPRStest("AT\r"); /** First test if everything is okay **/
  }
  else if (millis() - lastTest > testPeriod && testNumber == 1 && testAnswer == 1) {
    GPRStest("AT+CPIN?\r"); /**This is to check if SIM is unlocked. This sample assumes unlocked SIMs**/
  }
  else if (millis() - lastTest > testPeriod && testNumber == 2 && testAnswer == 1) {
    GPRStest("AT+CREG?\r"); /**This checks if SIM is registered or not**/
  }
  else if (millis() - lastTest > testPeriod && testNumber == 3 && testAnswer == 1) {
    GPRStest("AT+CGATT?\r"); /**Check if GPRS is attached or not**/
  }
  else if (millis() - lastTest > testPeriod && testNumber == 4 && testAnswer == 1) {
    GPRStest("AT+CIPSHUT\r"); /**Reset the IP session if any**/
  }
  else if (millis() - lastTest > testPeriod && testNumber == 5 && testAnswer == 1) {
    GPRStest("AT+CIPSTATUS\r");  /**Check if the IP stack is initialized**/
  }
  else if (millis() - lastTest > testPeriod && testNumber == 5 && testAnswer == 1) {
    GPRStest("AT+CIPSTATUS\r");  /**Check if the IP stack is initialized**/
  }
  else if (millis() - lastTest > testPeriod && testNumber == 6 && testAnswer == 1) {
    GPRStest("AT+CIPMUX=0\r");  /**To keep things simple, I’m setting up a single connection mode**/
  }
  else if (millis() - lastTest > testPeriod && testNumber == 7 && testAnswer == 1) {
    GPRStest("AT+CSTT=\"internet\",\"\",\"\"\r"); /**Start the task, based on the SIM card you are using, you need to know the APN, username and password for your service provider**/
  }
  else if (millis() - lastTest > testPeriod && testNumber == 8 && testAnswer == 1) {
    GPRStest("AT+CIICR\r"); /**Now bring up the wireless. Please note, the response to this might take some time**/
  }
  else if (millis() - lastTest > testPeriod && testNumber == 9 && testAnswer == 1) {
    GPRStest("AT+CIFSR\r"); /**Get the local IP address. Some people say that this step is not required, but if I do not issue this, it was not working for my case. So I made this mandatory, no harm.**/
  }
 // else if (millis() - lastTest > testPeriod && testNumber == 10 && testAnswer == 1) {
//    GPRStest("AT+CIPSTART=\"TCP\",\"portal.robotmonitor.com\",\"80\"\r"); /**Start the connection, TCP, domain name, port**/
 // }
   else if (millis() - lastTest > testPeriod && testNumber == 10 && testAnswer == 1) {
    GPRStest("AT+HTTPINIT\r"); /**Initialise the HTTP service**/
   }
   else if (millis() - lastTest > testPeriod && testNumber == 11 && testAnswer == 1) {
    GPRStest("AT+HTTPINIT=?\r"); /**Initialise the HTTP **/
   }
   else if (millis() - lastTest > testPeriod && testNumber == 12 && testAnswer == 1) {
    GPRStest("AT+HTTPACTION=0\r"); /**Initialise the HTTP methode (GET, POST, HEAD)**/
   }
  else if (millis() - lastTest > testPeriod && testNumber == 13 && testAnswer == 1) {
    GPRStest("AT+HTTPPARA=\"URL\",\"http://portal.robotmonitor.com/device-acces/write/?hash=40f805ca018487d70f51457762ba836e&data=ping\"\r"); /**Request initiation of data sending (the request)**/
     //delay(3000);
   }
  else if (millis() - lastTest > testPeriod && testNumber == 14 && testAnswer == 1) {
    GPRStest("AT+HTTPDATA=300,1500\r"); /**Request initiation of data sending (the request)**/
     //delay(3000);
   }
  else if (millis() - lastTest > testPeriod && testNumber == 15 && testAnswer == 1) {
    GPRStest("AT+HTTPREAD\r"); /**Request initiation of data sending (the request)**/
     //delay(3000);
   }
   /*  else if (millis() - lastTest > testPeriod && testNumber == 11 && testAnswer == 1) {
    GPRStest("\"\r\n"); /**Request initiation of data sending (the request)**/
//  }
// else if (millis() - lastTest > 500 && testNumber == 12 && testAnswer == 1) {
//    GPRStest("Host: portal.robotmonitor.com\r\n");  /**Just type anything for now**/
 // }
//  else if (millis() - lastTest > 500 && testNumber == 13 && testAnswer == 1) {
//    GPRStest("Connection: close\r\n\r\n");  /**Just type anything for now**/
//  }

 //else if (millis() - lastTest > 500 && testNumber == 14 && testAnswer == 1) {
    /**Now type the sequence #026. This tells the terminal.exe to send the hex code 0x1a (which is Ctrl+Z) to indicate end of data sending**/
    //GPRStestN(); // End AT command with a ^Z, ASCII code 26 // turn off module
  //}

  GPRSread();

}

void  GPRSread() {
  if (SIM900.available() > 0) {
    char c = SIM900.read();
    //Serial.print(c, DEC);
    //Serial.print(".");
    if (c != '\r') {
      temp = temp + c;
    }
    else if (c == '\r') {
      //Serial.print("\\r");
      //Serial.println();
      Serial.println(temp);
      testAnswer = 1;
      temp = "";
      delay(100);
    }
  } else {
    if (testNumber == 14) testAnswer = 1;
    delay(100);
  }
}
hubacekp
Příspěvky: 259
Registrován: 24 úno 2013, 13:40

Re: GSM_SIM900

Příspěvek od hubacekp »

A nezapomen napajet shield samoststne.
Arduino ho neutahne.
Jirka
Příspěvky: 55
Registrován: 18 lis 2015, 12:06

Re: GSM_SIM900

Příspěvek od Jirka »

Ahoj,
díky za pomoc. Že je potřeba dobrý zdroj jsem už krvavě (lopotně) zjistil - nechodí třeba jen některé funkce.
Při psaní jsem vycházel právě z prvního jmenovaného zdroje.
S tím časem jsem laboroval přes tlačítko stačí cca 1-2 sec. (teď jsem tam dal přes relé 5 sec.).
Ale s relátkem se mi to nelíbí (a optronem nelze).
Jen ještě další otázečka – chystám se časem dodělat i příposlech (abych zavolal a mohl poslouchat audio vstup). Nemáš s tím zkušenost? Neumím anglicky takže tápu.
hubacekp
Příspěvky: 259
Registrován: 24 úno 2013, 13:40

Re: GSM_SIM900

Příspěvek od hubacekp »

Zkusenosti s audiem nemam, ale melo by stacit, aby pri nejakem eventu (sms,zmena na pinu) arduino pres AT prikaz zavolalo na definovane cislo, kde po zvednuti muzes poslouchat. Jen do GSM shieldu musis pripojit mikrofon.
Do anglictiny se zakousni a chod se slovnikem v kapse. Vyplati se to.
Odpovědět