You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have started my first IoT project in the last few days. Based on arduino and the DEV board ESP-12S-A9-A9G-GPRS-Node-v1.0.
I would like to share my source code to discuss the following problems.
The A9G module does not start at every startup. Any Idea how I can ensure that the A9G Modul starts and if not to restart the System?
After about 1.5 hours to 2 hours, the GPS stop working. Any Idea how I can fix this bug?
Is there an elegant solution how to select the WIFI, enter the password and then save it on the ESP for connecting?
Last but not least, some Idea to optimize the code?
I hope you can help me to fix point 1 an 2 and have some good ideas for point 3.
INO
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266WebServer.h>
#include <EEPROM.h>
// A9G Config
#define A9G_PON 16 //ESP12 GPIO16 A9/A9G POWON
#define A9G_POFF 15 //ESP12 GPIO15 A9/A9G POWOFF
#define A9G_WAKE 13 //ESP12 GPIO13 A9/A9G WAKE
#define A9G_LOWP 2 //ESP12 GPIO2 A9/A9G ENTER LOW POWER MODULE
#define DEBUG false
void handleInterrupt();
int A9GPOWERON();
int counter = 1;
// Serialize varibles
String Meter = "";
String LAT= "";
String LNG = "";
String Sec = "";
String Spe = "";
String GPSdate = "";
String URL = "http://**#your_domain#**/write.php";
// TinyGPS++ configuration
static const int RXPin = 14, TXPin = 12;
static const uint32_t GPSBaud = 115200;
// The TinyGPS++ object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
// Setup WIFI and Access-Point
const char* APpassword = "1234567890";
const char* ssid = "";
const char* password = "";
int threshold = 39;
int x = 0;
// Setup Webserver
ESP8266WebServer server(80);
void setup()
{
Serial.begin(115200);
ss.begin(GPSBaud);
// Start Access Point and WIFI - Start
String s;
s = ESP.getChipId();
String hostname;
hostname = "LocateMe_" + s;
const char* APssid = hostname.c_str();
Serial.print("Configuring access point...");
WiFi.mode(WIFI_AP_STA);
WiFi.softAP(APssid, APpassword);
delay(500);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED && x < threshold) {
delay(500);
Serial.print(".");
counter++;
x++;
}
if (x >= threshold) { // bail out on sensor detect
x = 0;
Serial.print("Not Conneted");
//break;
}
delay(1000);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
Serial.print("AP Name: ");
Serial.println(APssid);
server.on("/", handleRoot);
server.begin();
Serial.println("HTTP server started");
delay(2000);
// Start Access Point and WIFI - Ende
// Setup A9G - Start
pinMode(A9G_PON, OUTPUT);//LOW LEVEL ACTIVE
pinMode(A9G_POFF, OUTPUT);//HIGH LEVEL ACTIVE
pinMode(A9G_LOWP, OUTPUT);//LOW LEVEL ACTIVE
digitalWrite(A9G_PON, HIGH);
digitalWrite(A9G_POFF, LOW);
digitalWrite(A9G_LOWP, HIGH);
Serial.println("After 2s A9G will POWER ON.");
delay(2000);
if(A9GPOWERON()==1)
{
Serial.println("A9G POWER ON.");
}
Serial.println("Enale the GPS");
sendData("AT+GPS=1",1000,DEBUG);
delay(2000);
pinMode(A9G_WAKE, INPUT);//interruptPin
attachInterrupt(digitalPinToInterrupt(A9G_WAKE), handleInterrupt, RISING);
delay(2000);
// Setup A9G - Ende
}
void loop()
{
sendData("AT+GPS=1",1000,DEBUG);
server.handleClient();
delay(2500);
ss.println("AT+GPSRD=1");
smartDelay(1000);
if(gps.satellites.isValid()){
String SumSat = String(gps.satellites.value());
}
if(gps.altitude.isValid()){
Meter = String(gps.altitude.meters());
}
if(gps.date.isValid()){
char sz[32];
sprintf(sz, "%02d.%02d.%02d ", gps.date.day(), gps.date.month(), gps.date.year());
char tz[32];
sprintf(tz, "%02d:%02d:%02d", gps.time.hour(), gps.time.minute(), gps.time.second());
GPSdate=String(sz)+String(tz);
//Serial.println(GPSdate);
}
if(gps.location.isValid()){
LAT = String(gps.location.lat(),6);
LNG = String(gps.location.lng(),6);
String LAT_latest = LAT;
String LNG_latest = LNG;
}
if(gps.speed.isValid()){
Spe = String(gps.speed.kmph(),2);
}
// JSON Request - Start
if(WiFi.status() == WL_CONNECTED){
if(LAT != ""){
Serial.println("Request");
HTTPClient http; //Object of class HTTPClient
String CallUrl = URL + "?lat=" + LAT + "&lng=" + LNG + "&t=" + urlencode(GPSdate) + "&m=" + urlencode(Meter) + "&s=" + urlencode(Spe);
String Test = urlencode(CallUrl);
http.begin(CallUrl);
int httpCode = http.GET();
Serial.println(CallUrl);
Serial.println(httpCode);
if (httpCode > 0)
{
String payload = http.getString(); //Get the request response payload
Serial.println(payload); //Print the response payload
}
http.end(); //Close connection
smartDelay(1000);
}
else{
Serial.println("No Data");
}
}
else{
Serial.println("No Call");
}
// end LOOP
}
// This custom version of delay() ensures that the gps object
// is being "fed".
static void smartDelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (ss.available())
gps.encode(ss.read());
} while (millis() - start < ms);
}
void handleInterrupt() {
Serial.println("An interrupt has occurred.");
}
String sendData(String command, const int timeout, boolean debug)
{
String response = "";
ss.println(command);
long int time = millis();
while( (time+timeout) > millis())
{
while(ss.available())
{
char c = ss.read();
response+=c;
}
}
if(debug)
{
Serial.print(response);
}
return response;
}
int A9GPOWERON()
{
digitalWrite(A9G_PON, LOW);
delay(3000);
digitalWrite(A9G_PON, HIGH);
delay(5000);
String msg = String("");
msg=sendData("AT",1000,DEBUG);
if( msg.indexOf("ok") >= 0 ){
Serial.println("GET OK");
return 1;
}
else {
Serial.println("NOT GET OK");
return 0;
}
}
int A9GPOWEROFF()
{
digitalWrite(A9G_POFF, HIGH);
delay(3000);
digitalWrite(A9G_POFF, LOW);
delay(5000);
String msg = String("");
msg=sendData("AT",1000,DEBUG);
if( msg.indexOf("ok") >= 0 ){
Serial.println("GET OK");
return 1;
}
else {
Serial.println("NOT GET OK");
return 0;
}
}
int A9GENTERLOWPOWER()
{
String msg = String("");
msg=sendData("AT+SLEEP=1",1000,DEBUG);
if( msg.indexOf("OK") >= 0 ){
digitalWrite(A9G_LOWP, LOW);
return 1;
}
else {
return 0;
}
}
String urldecode(String str)
{
String encodedString="";
char c;
char code0;
char code1;
for (int i =0; i < str.length(); i++){
c=str.charAt(i);
if (c == '+'){
encodedString+=' ';
}else if (c == '%') {
i++;
code0=str.charAt(i);
i++;
code1=str.charAt(i);
c = (h2int(code0) << 4) | h2int(code1);
encodedString+=c;
} else{
encodedString+=c;
}
yield();
}
return encodedString;
}
String urlencode(String str)
{
String encodedString="";
char c;
char code0;
char code1;
char code2;
for (int i =0; i < str.length(); i++){
c=str.charAt(i);
if (c == ' '){
encodedString+= '+';
} else if (isalnum(c)){
encodedString+=c;
} else{
code1=(c & 0xf)+'0';
if ((c & 0xf) >9){
code1=(c & 0xf) - 10 + 'A';
}
c=(c>>4)&0xf;
code0=c+'0';
if (c > 9){
code0=c - 10 + 'A';
}
code2='\0';
encodedString+='%';
encodedString+=code0;
encodedString+=code1;
//encodedString+=code2;
}
yield();
}
return encodedString;
}
unsigned char h2int(char c)
{
if (c >= '0' && c <='9'){
return((unsigned char)c - '0');
}
if (c >= 'a' && c <='f'){
return((unsigned char)c - 'a' + 10);
}
if (c >= 'A' && c <='F'){
return((unsigned char)c - 'A' + 10);
}
return(0);
}
/* Go to http://192.168.4.1 in a web browser */
void handleRoot() {
server.send(200, "text/html", "You are connected");
}
// AP ENDE
chesterrush, conseguiu fazer funcionar com o projeto com a placa ESP-12S-A9-A9G-GPRS-Node-v1.0. A biblioteca TinyGPS ++ deu certo nessa placa? estou num projeto parecido e precisava dessas informações. obrigado
Library works well.
If you find a way to use the a9/a9g module I will be very happy if you can
share that with me.
maykonfpp ***@***.***> schrieb am Do., 2. Dez. 2021, 21:46:
Mas a biblioteca funciona nessa placa ESP-12S-A9-A9G-GPRS-Node-v1.0 ?? Estou fazendo alguns teste e não funciona. Para funcionar (retornar a latitude e longitude) utilizei os comandos AT
Hi everyone,
I have started my first IoT project in the last few days. Based on arduino and the DEV board ESP-12S-A9-A9G-GPRS-Node-v1.0.
I would like to share my source code to discuss the following problems.
I hope you can help me to fix point 1 an 2 and have some good ideas for point 3.
INO
PHP
HTML
CSV
The text was updated successfully, but these errors were encountered: