Bonjour,
Je suis en train de réaliser un projet et pour celui-ci j'ai fait l'acquisition d'un module SIM808 de chez DFRobot. Le but est d'obtenir les coordonnées GPS (latitude et longitude) ainsi que la vitesse pour ensuite les envoyer sur un Dashboard, ici mon choix s'est porté sur Freeboard.io avec l'utilisation de dweet.io . Pour ce faire, j'utilise donc le module GPS, qui me renvoie les coordonnées sans problème. Puis je souhaite les envoyer à l'aide d'une requête HTTP pour l'instant. Ces deux parties de programme fonctionne séparément. Cependant lors de la fusion, il m'est impossible d'établir la liaison avec le site de dweet, j'ai systématiquement le renvoie de connect error. Après plusieurs recherches, o me signale que les modules ont du mal à travailler en même temps, je force donc la séparation des deux en coupant les modules lorsqu'ils sont inactifs et à leurs utilisation à l'aide de condition. Malgré cela, rien ne change.
Ainsi, j'aurai aimé savoir si vous aviez des pistes de solutions, peut être que mon GPS n'est pas bien déconnecté, ou alors autre chose.
Voici mon code :
/*!
@file GPS_carteSD.ino
@brief Get GPS data
@details 1. This example is used to test SIM808 GPS/GPRS/GSM Shield's reading GPS data and sending them on dweet.io.
@n 2. Open the SIM808_GetGPS example or copy these code to your project
@n 3. Download and dial the function switch to Arduino
@n 4. open serial helper
@n 4. Place it outside, waiting for a few minutes and then it will send GPS data to serial
@author Quentin Caillou
@version V1.0
@date 2022-06-15
*/
#include <DFRobot_SIM808.h>
#include <SoftwareSerial.h>
//*********************Initialisation GPS********************
/*
Si on branche le module GPS de sa PIN RX et TX vers des pins de l'arduino, on utilise le code suivant
*/
//#define PIN_TX 3
//#define PIN_RX 2
//SoftwareSerial mySerial(PIN_TX,PIN_RX);
//DFRobot_SIM808 sim808(&mySerial);//Connect RX,TX,PWR,
// On utilise cette ligne de code si le module 808 est inséré sur l'arduino UNO
DFRobot_SIM808 sim808(&Serial);
//************************Initialisation envoie de données*****************
char buffer[512];
int i = 1;
int lati = 56;
int longi = 24;
int vitesse = 25;
int fonctio;
int arret;
String http_cmd2;
void setup() {
Serial.begin(9600);
Serial.println(F("Programme pour pouvoir lire et écrire des données sur la carte SD"));
//******** Initialize sim808 module *************
while (!sim808.init()) {
delay(1000);
Serial.print(F("Sim808 init error\r\n"));
}
//************* Turn on the GPS power************
if ( sim808.attachGPS()) {
Serial.println(F("Open the GPS power success"));
Serial.println(sim808.GPSdata.lat, 6);
}
else
{
Serial.println(F("Open the GPS power failure"));
}
/*
//*********** Attempt DHCP *******************
while (!sim808.join(F("websfr"))) {
Serial.println(F("Sim808 join network error"));
delay(2000);
}
//************ Successful DHCP ****************
Serial.print(F("IP Address is "));
Serial.println(sim808.getIPAddress());
Serial.println(F("Fin Initialisation "));
*/
}
void loop() {
//************** Get GPS data *******************
if ((sim808.getGPS()) && (i == 1))
{
Serial.print(sim808.GPSdata.year);
Serial.print("/");
Serial.print(sim808.GPSdata.month);
Serial.print("/");
Serial.print(sim808.GPSdata.day);
Serial.print(" ");
Serial.print(sim808.GPSdata.hour);
Serial.print(":");
Serial.print(sim808.GPSdata.minute);
Serial.print(":");
Serial.println(sim808.GPSdata.second);
Serial.print(F("latitude :"));
Serial.println(sim808.GPSdata.lat, 6);
Serial.print(F("longitude :"));
Serial.println(sim808.GPSdata.lon, 6);
Serial.print(F("speed_kph :"));
Serial.println(sim808.GPSdata.speed_kph);
lati = sim808.GPSdata.lat;
longi = sim808.GPSdata.lon;
vitesse = sim808.GPSdata.speed_kph;
Serial.println(lati);
Serial.println(longi);
Serial.println(vitesse);
if (vitesse < 1) {
fonctio = 0;
arret = 1;
}
else {
fonctio = 1;
arret = 0;
}
Serial.println(fonctio);
Serial.println(arret);
//************* Turn off the GPS power ************
sim808.detachGPS();
i = 0;
delay(10000);
}
if (i == 0)
{
//*********** Attempt DHCP *******************
while (!sim808.join(F("websfr"))) {
Serial.println(F("Sim808 join network error"));
delay(2000);
}
//************ Successful DHCP ****************
Serial.print(F("IP Address is "));
Serial.println(sim808.getIPAddress());
delay(1000);
//*********** Establish a TCP connection ************
if (!sim808.connect(TCP, "dweet.io", 80)) {
Serial.println(F("Connect error"));
}
else {
Serial.println(F("Connect dweet.io success"));
}
http_cmd2 = "GET http://dweet.io/dweet/for/arduino?lat=";
http_cmd2 = http_cmd2 + String(lati);
http_cmd2 = http_cmd2 + "&long=-";
http_cmd2 = http_cmd2 + String(longi);
http_cmd2 = http_cmd2 + "&cinematique=";
http_cmd2 = http_cmd2 + String(vitesse);
http_cmd2 = http_cmd2 + "&fonctionnementoui";
http_cmd2 = http_cmd2 + String(fonctio);
http_cmd2 = http_cmd2 + "&arret";
http_cmd2 = http_cmd2 + String(arret);
http_cmd2 = http_cmd2 + " HTTP/1.0\r\n\r\n";
int str_length = http_cmd2.length() + 1;
char http_cmd_array[str_length];
http_cmd2.toCharArray(http_cmd_array, str_length);
Serial.println(http_cmd_array);
//*********** Send a GET request *****************
Serial.println(F("waiting to fetch..."));
sim808.send(http_cmd_array, str_length - 1);
while (true) {
int ret = sim808.recv(buffer, sizeof(buffer) - 1);
if (ret <= 0) {
Serial.println(F("fetch over..."));
break;
}
buffer[ret] = '\0';
Serial.print("Recv: ");
Serial.print(ret);
Serial.print(" bytes: ");
Serial.println(buffer);
break;
}
//************* Close TCP or UDP connections **********
sim808.close();
// Disconnect wireless connection, Close Moving Scene *******
sim808.disconnect();
i = 1;
delay(1000);
}
}
/* Fonction permettant de créer la requete HTML.
String getDweetString() {
int i = 0;
//use the dweet GET to post to dweet
String dweetHttpGet = "GET http://dweet.io/dweet/for/arduino?";
for (i = 0; i < (numberVariables); i++) {
if (i == numberVariables - 1) {
//the lastone doesnt have a "&" at the end
dweetHttpGet = dweetHttpGet + String(arrayVariableNames[i]) + "=" + String(arrayVariableValues[i]);
}
else
dweetHttpGet = dweetHttpGet + String(arrayVariableNames[i]) + "=" + String(arrayVariableValues[i]) + "&";
}
dweetHttpGet = dweetHttpGet + " HTTP/1.0\r\n\r\n";
return dweetHttpGet;//this is our freshly made http string request
}*
*/
Voici ce que je peux voir :
Programme pour pouvoir lire et écrire des données sur la carte SD
AT
AT+CFUN=1
AT+CPIN?
AT+CGNSPWR=1
AT+CGNSTST=1
Open the GPS power success
0.000000
2022/6/16 11:49:54
latitude :46.856891
longitude :1.038200
speed_kph :1.89
46
1
1
1
0
AT+CGNSPWR=0
AT+CSTT="websfr","",""
AT+CIICR
AT+CIFSR
IP Address is 10.228.16.194
AT+CIPSTART="TCP","dweet.io",80
Connect error
GET http://dweet.io/dweet/for/arduino?lat=46&long=-1&cinematique=1&fonctionnementoui1&arret0 HTTP/1.0
waiting to fetch...
AT+CIPSEND=106
Recv: 511 bytes: ,82,026,33,16,48,177,,08,47,298,32,23,41,063,37*7F
$GPGSV,2,2,08,18,10,059,32,30,08,324,17,15,05,036,18,21,,,25*45
$GPRMC,115016.000,A,4651.4103,N,00102.2929,W,1.00,178.46,160622,,,A*71
$GPVTG,178.46,T,,M,1.00,N,1.86,K,A*3F
$GPGGA,115017.000,4651.4100,N,00102.2930,W,1,5,2.62,126.6,M,48.4,M,,*4D
$GPGLL,4651.4100,N,00102.2930,W,115017.000,A,A*40
$GPGSA,A,3,23,27,18,08,30,,,,,,,,2.80,2.62,0.99*08
$GPGSV,2,1,08,27,82,026,34,16,48,177,,08,47,298,33,23,41,063,37*79
$GPGSV,2,2,08,18,10,059,31,30,08,324,17
AT+CIPSTATUS
AT+CIPSHUT
2022/6/16 11:50:19
latitude :46.856826
longitude :1.038217
speed_kph :2.04
46
1
2
1
0
AT+CGNSPWR=0
AT+CSTT="websfr","",""
AT+CIICR
AT+CIFSR
Sim808 join network error
AT+CSTT="websfr","",""
AT+CIICR
AT+CIFSR
Sim808 join network error
AT+CSTT="websfr","",""
AT+CIICR
AT+CIFSR
Sim808 join network error
AT+CSTT="websfr","",""
AT+CIICR
AT+CIFSR
Sim808 join network error
AT+CSTT="websfr","",""
AT+CIICR
AT+CIFSR
IP Address is 10.228.16.194
AT+CIPSTART="TCP","dweet.io",80
Connect error
GET http://dweet.io/dweet/for/arduino?lat=46&long=-1&cinematique=2&fonctionnementoui1&arret0 HTTP/1.0
waiting to fetch...
AT+CIPSEND=106
Recv: 511 bytes: V,3,1,09,27,82,033,32,08,48,299,32,16,47,176,,23,41,062,40*7B
$GPGSV,3,2,09,21,31,247,25,07,15,297,29,18,09,059,28,30,08,323,19*75
$GPGSV,3,3,09,15,05,035,18*4E
$GPRMC,115137.000,A,4651.4013,N,00102.2928,W,0.69,5.74,160622,,,A*76
$GPVTG,5.74,T,,M,0.69,N,1.27,K,A*30
$GPGGA,115138.000,4651.4015,N,00102.2928,W,1,7,1.57,114.0,M,48.4,M,,*4D
$GPGLL,4651.4015,N,00102.2928,W,115138.000,A,A*40
$GPGSA,A,3,23,27,21,18,08,30,07,,,,,,2.20,1.57,1.54*03
$GPGSV,3,1,09,27,82,033,33,08,48,299,33,16,47,176,,23,41,062
AT+CIPSTATUS
AT+CIPSHUT
Pour informations, mon module est connecté directement sur ma carte arduino et est alimenté par une batterie 11.1V et 2000mAh.
Merci pour votre aide

