Mais c'est un truc de ouf,
Y a pas des commande AT pour tous les modules?
Sais-tu ou je peux commander un SIM900? J'ai besoin d'un tout petit
Si j'ai ce code mais il ne fonctionne que lors du premier passage dans la loop(), après, il se bloque dans la function
void cellOutputForever() {
Serial.println("Looping forever displaying cell module output...");
while(1) {
if(cell.available()>0) {
Serial.print((char)cell.read());
}
}
}
ou après le premoer envoi au server,
il se bloque et n'arrive plus recevoir un aknoledge du server
while (1) {
cell.println("AT+SDATASTATUS=1"); // we'll get back SOCKSTATUS and then OK
String s = getMessage(); // we want s to contain the SOCKSTATUS message
if (s == "+STCPD:1") // this means server sent data. cool, but we want to see SOCKSTATUS, so let's get next message
s = getMessage();
if (s == "+STCPC:1") // this means socket closed. cool, but we want to see SOCKSTATUS, so let's get next message
s = getMessage();
waitFor("OK");
if (!s.startsWith("+SOCKSTATUS")) {
Serial.println(F("Wait, this isn't the SOCKSTATUS message!"));
cellOutputForever(); // something went wrong
}
if (checkSocketString(s) == packetLength) // checks that packetLength bytes have been acknowledged by server
break; // we're good!
else {
Serial.println(F("Sent data not yet acknowledged by server, waiting 1 second and checking again."));
delay(1000);
}
}
Serial.println("Yes! Sent data acknowledged by server!");
C'est asesez dur d'etre précis, mais voici le code complet
/* SM5100B-GPRS
* this Arduino program sends an HTTP request over GPRS using the SM5100B GSM shield
* author: http://toby.is
* more info: http://github.com/tobek/SM5100B-GPRS
*/
// include the SoftwareSerial library to send serial commands to the cellular module:
#include <SoftwareSerial.h>
SoftwareSerial cell(2,3); // Create a 'fake' serial port. Pin 2 is the Rx pin, pin 3 is the Tx pin. connect this to the GSM module
const String apn = "internet"; // access-point name for GPRS
const String ip = "80.00.000.00"; // IP address of server we're connecting to
const String host = "www.qqq-qqq.net"; // required in HTTP 1.1 - what's the name of the host at this IP address?
const String request = "GET /temp/updatesql.php?lat=1.10&long=1.20&alt=1.30&speed=1.40&course=1.50&date=2013-4-10&time=19:12:00 HTTP/1.1";
const String useragent = "Mozilla/5.0"; // for our purposes the user agent doesn't matter - if I understand correctly it's helpful to use something generic the server will recognize
int GPRS_registered = 0;
int GPRS_AT_ready = 0;
/* this will send the following packet:
*
* GET /m/testpage.php?data=testing HTTP/1.1
* Host: avantari.co.uk
* User-Agent: Mozilla/5.0
*
* this is the equivalent of visiting http://avantari.co.uk/m/testpage.php?data=testing
*/
void setup()
{
//Initialize serial ports for communication with computer
Serial.begin(9600);
Serial.println(F(""));
Serial.println(F("Starting SM5100B Communication..."));
cell.begin(9600);
/*
waitTil("+SIND: 4"); // keep printing cell output til we get "+SIND: 4"
Serial.println("Module ready");
*/
Serial.println(F("Wait for module is registered (+SIND: 11) and ready (+SIND: 4) ..."));
while (GPRS_registered == 0 || GPRS_AT_ready == 0) {
String ready = getMessage();
if(ready == "+SIND: 1"){
Serial.println(F("SIM is inserted ..."));
}
if(ready == "+SIND: 10,\"SM\",1,\"FD\",1,\"LD\",1,\"MC\",1,\"RC\",1,\"ME\",1"){
Serial.println(F("SIM is ready ..."));
}
if(ready == "+SIND: 11"){
GPRS_registered = 1;
Serial.println(F("Module is registered to network ..."));
}
if(ready == "+SIND: 3"){
Serial.println(F("GPRS is partially ready ..."));
}
if(ready == "+SIND: 4"){
GPRS_AT_ready = 1;
Serial.println(F("GPRS is ready ..."));
}
if(ready == "+SIND: 7"){
Serial.println(F("Emergency only ..."));
}
}
//waitTil("+SIND: 4"); // keep printing cell output til we get "+SIND: 4"
Serial.println(F(" "));
Serial.println(F("READY TO GO"));
}
void loop()
{
Serial.println(F("Attaching GPRS..."));
cell.println("AT+CGATT=1");
waitFor("OK");
Serial.println(F("Setting up PDP Context..."));
cell.println("AT+CGDCONT=1,\"IP\",\""+apn+"\"");
waitFor("OK");
Serial.println(F("Activating PDP Context..."));
cell.println("AT+CGACT=1,1");
waitFor("OK");
Serial.println(F("Configuring TCP connection to TCP Server..."));
cell.println("AT+SDATACONF=1,\"TCP\",\""+ip+"\",80");
waitFor("OK");
Serial.println(F("Starting TCP Connection..."));
cell.println("AT+SDATASTART=1,1");
waitFor("OK");
delay(5000); // wait for the socket to connect
// now we'll loop forever, checking the socket status and only breaking when we connect
while (1) {
Serial.println(F("Checking socket status:"));
cell.println("AT+SDATASTATUS=1"); // we'll get back SOCKSTATUS and then OK
String sockstat = getMessage();
waitFor("OK");
if (sockstat=="+SOCKSTATUS: 1,0,0104,0,0,0") {
Serial.println(F("Not connected yet. Waiting 1 second and trying again."));
delay(1000);
}
else if (sockstat=="+SOCKSTATUS: 1,1,0102,0,0,0") {
Serial.println(F("Socket connected"));
break;
}
else {
Serial.println(F("We didn't expect that."));
cellOutputForever();
}
}
// we're now connected and can send HTTP packets!
int packetLength = 26+host.length()+request.length()+useragent.length(); // 26 is size of the non-variable parts of the packet, see SIZE comments below
Serial.println(F("Sending HTTP packet..."));
cell.print("AT+SDATATSEND=1,"+String(packetLength)+"\r");
waitFor('>'); // wait for GSM module to tell us it's ready to recieve the packet
cell.print(request+"\r\n"); // SIZE: 2
cell.print("Host: "+host+"\r\n"); // SIZE: 8
cell.print("User-Agent: "+useragent+"\r\n\r\n"); // SIZE: 16
cell.write(26); // ctrl+z character: send the packet
waitFor("OK");
// now we're going to keep checking the socket status forever
// break when the server tells us it acknowledged data
while (1) {
cell.println("AT+SDATASTATUS=1"); // we'll get back SOCKSTATUS and then OK
String s = getMessage(); // we want s to contain the SOCKSTATUS message
if (s == "+STCPD:1") // this means server sent data. cool, but we want to see SOCKSTATUS, so let's get next message
s = getMessage();
if (s == "+STCPC:1") // this means socket closed. cool, but we want to see SOCKSTATUS, so let's get next message
s = getMessage();
waitFor("OK");
if (!s.startsWith("+SOCKSTATUS")) {
Serial.println(F("Wait, this isn't the SOCKSTATUS message!"));
cellOutputForever(); // something went wrong
}
if (checkSocketString(s) == packetLength) // checks that packetLength bytes have been acknowledged by server
break; // we're good!
else {
Serial.println(F("Sent data not yet acknowledged by server, waiting 1 second and checking again."));
delay(1000);
}
}
Serial.println("Yes! Sent data acknowledged by server!");
// we could skip the checking of SOCKSTATUS in the above while-loop
// instead we could just wait for one or both of these:
//waitTil("+STCPD:1"); // this means data is received
//waitTil("+STCPC:1"); // this means socket is closed
// TODO: actually check if we received data, don't just do this blindly
// Serial.println(F("Reading data from server..."));
// cell.println("AT+SDATAREAD=1"); // how we read data server has sent
// WARNING: this might not work - software serial can be too slow for receiving data
//cellHexForever(); // useful for debugging
// cellOutputForever(); // just keep printing whatever GSM module is telling us
}
Je suis limité dans le nombre de caratères autorisés dans ce poste. Je colle la suite su code, qui suit la finc de fubction loop() dans un post suivant