Arduino - Uso de ESP32 y sim800l

 
Vista:
sin imagen de perfil
Val: 3
Ha disminuido su posición en 5 puestos en Arduino (en relación al último mes)
Gráfica de Arduino

Uso de ESP32 y sim800l

Publicado por Andres (3 intervenciones) el 29/01/2020 05:14:01
Hola a todos, he estado probando un sim800l con un arduino uno para enviar datos (inicialmente declarados como constantes) a una base de datos en un servidor y hasta ahora he conseguido que funcione. El código que utilizo es el siguiente:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// This program collects data and reports it to a URL on the internet.
// To eliminate unecessary data usage, the data is reported using a HEAD method.
// Uses a SIM800L to connect to the GPRS network.
 
#include <SoftwareSerial.h>
 
//Arduino UNO
#define GSM_TX 7      //To RX pin of SIM800L
#define GSM_RX 8      //To TX pin of SIM800L
#define GSM_RESET 6
#define STATUS 13
 
// Set the GPRS Access Point Name (APN) to suit your SIM card.
#define AccessPointName "internet.comcel.com.co"
// Set the address of the server where the measurements should be reported.
#define HTTPserver "http://test777.000webhostapp.com"
// Set the URL of the program that receives the measurements.
//#define HTTPurl "/programa1.php?"
#define HTTPurl "/programa2.php?"
 
SoftwareSerial GSM_serial(GSM_RX, GSM_TX);
// Note that only GSM_TX is used. GSM_RX is not used.
 
void connect()
{
  GSM_serial.print("+++");
  delay(1000);
  GSM_serial.print("AT\r\n");
  delay(1000);
  GSM_serial.print("ATE1\r\n"); // Turn on echo, makes it easier to debug the SIM800L
  delay(1000);
  GSM_serial.print("AT+CGATT=1\r\n");
  delay(1000);
  GSM_serial.print("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"\r\n");
  delay(1000);
  GSM_serial.print("AT+SAPBR=3,1,\"APN\",\"");
  GSM_serial.print(AccessPointName);
  GSM_serial.print("\"\r\n");
  delay(1000);
  GSM_serial.print("AT+SAPBR=1,1\r\n");
  delay(3000);
}
 
 
void disconnect()
{
  GSM_serial.print("AT+SAPBR=0,1\r\n");
}
 
 
//void HTTPhead(char *message)
void HTTPhead(char *message, char *message2)
{
  digitalWrite(STATUS, 1);
  connect();
  GSM_serial.print("AT+HTTPINIT\r\n");
  delay(1000);
  GSM_serial.print("AT+HTTPPARA=\"CID\",1\r\n");
  delay(1000);
  GSM_serial.print("AT+HTTPPARA=\"URL\",\"");
  GSM_serial.print(HTTPserver);
  GSM_serial.print(HTTPurl);
  GSM_serial.print(message);
  GSM_serial.print("&");
  GSM_serial.print(message2);
  GSM_serial.print("\"\r\n");
  delay(1000);
  GSM_serial.print("AT+HTTPACTION=2\r\n"); // Request header only, reduces data usage
  delay(3000);
  GSM_serial.print("AT+HTTPTERM\r\n");
  disconnect();
  digitalWrite(STATUS, 0);
  delay(10000);
}
 
 
void reset_GSM()
{
  digitalWrite(STATUS, 1);
  digitalWrite(GSM_RESET, 0);
  delay(100);
  digitalWrite(GSM_RESET, 1);
  digitalWrite(STATUS, 0);
  delay(10000);
}
 
 
void low_power_GSM()
{
  GSM_serial.print("AT+CFUN=0,1\r\n");
  delay(10000);
}
 
 
void full_power_GSM()
{
  GSM_serial.print("AT+CFUN=1,1\r\n");
  delay(10000);
}
 
 
void setup()
{
  Serial.begin(9600);
  Serial.println("Reset");
 
  pinMode(GSM_RESET, OUTPUT);
  digitalWrite(GSM_RESET, 1);
 
  pinMode(STATUS, OUTPUT);
  digitalWrite(STATUS, 0);
 
  GSM_serial.begin(9600);
  reset_GSM();
}
 
 
 
void loop()
{
  char buf[20];
  char buf2[20];
 
  float d1 = 10;                            // Read data and convert to string "dato=nn.n"
  float d2 = 20;
  dtostrf(d1, 3, 1, buf);
  dtostrf(d2, 3, 1, buf2);
 
  String message = String("dato=");
  message += buf;
  String message2 = String("dato2=");
  message2 += buf2;
 
  full_power_GSM();                        // Move to full power mode to get ready to send data.
  message.toCharArray(buf, 20);            // Prepare message.
  message2.toCharArray(buf2, 20);
  //HTTPhead(buf);
  HTTPhead(buf, buf2);                           // Report measurement by sending HEAD message to internet URL.
  reset_GSM();                             // Reset SIM800L to prevent unwanted data usage.
  low_power_GSM();                         // SIM800L uses a lot of power if it is left if full power mode.
  delay(10);
 
}

He querido implementar este codigo para una ESP32 haciendo los respectivos cambios pero tengo entendido que la librería SoftwareSerial de arduino no funciona bien con esta tarjeta, por lo que intente usando la libreria correspondiente EspSoftwareSerial pero sin exito. Para aprovechar los puertos propios de la tarjeta tambien reemplace SoftwareSerial por HardwareSerial pero hasta ahora no he logrado una comunicacion exitosa.
Ademas durante mis pruebas en ocasiones he obtenido el siguiente error:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Guru Meditation Error: Core  0 panic'ed (StoreProhibited)
. Exception was unhandled.
Core 0 register dump:
PC      : 0x4008cf79  PS      : 0x00060033  A0      : 0x8008b9b8  A1      : 0x3ffb05a0
A2      : 0x3ffb3b48  A3      : 0x3ffcec90  A4      : 0x3ffbba7c  A5      : 0x000000ff
A6      : 0x00000001  A7      : 0x00000000  A8      : 0x3ffb7946  A9      : 0x00000000
A10     : 0x3ffcd1c0  A11     : 0x00000000  A12     : 0x00060021  A13     : 0x00000001
A14     : 0x00060021  A15     : 0x00060023  SAR     : 0x00000011  EXCCAUSE: 0x0000001d
EXCVADDR: 0x00000004  LBEG    : 0x00000000  LEND    : 0x00000000  LCOUNT  : 0x00000000
Core 0 was running in ISR context:
EPC1    : 0x4008cf79  EPC2    : 0x00000000  EPC3    : 0x00000000  EPC4    : 0x4008a78a
Backtrace: 0x4008cf79:0x3ffb05a0 0x4008b9b5:0x3ffb05c0 0x4008a1a3:0x3ffb05e0 0x4008c525:0x3ffb0600 0x40082582:0x3ffb0610 0x400d374b:0x00000000

Algún consejo de como poder lograr implementar esto sobre la ESP32? Gracias de antemano.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder