4
4
5
5
#include < SIM808.h>
6
6
#include < ArduinoLog.h>
7
- #include < SoftwareSerial.h>
7
+
8
+ #if defined(__AVR__)
9
+ #include < SoftwareSerial.h>
10
+ #define SIM_SERIAL_TYPE SoftwareSerial // /< Type of variable that holds the Serial communication with SIM808
11
+ #define SIM_SERIAL SIM_SERIAL_TYPE (SIM_TX, SIM_RX) // /< Definition of the instance that holds the Serial communication with SIM808
12
+
13
+ #define STRLCPY_P (s1, s2) strlcpy_P(s1, s2, BUFFER_SIZE)
14
+ #else
15
+ #include < HardwareSerial.h>
16
+ #define SIM_SERIAL_TYPE HardwareSerial // /< Type of variable that holds the Serial communication with SIM808
17
+ #define SIM_SERIAL SIM_SERIAL_TYPE (2 ) // /< Definition of the instance that holds the Serial communication with SIM808
18
+
19
+ #define STRLCPY_P (s1, s2) strlcpy(s1, s2, BUFFER_SIZE)
20
+ #endif
8
21
9
22
#define SIM_RST 5 // /< SIM808 RESET
10
23
#define SIM_RX 6 // /< SIM808 RXD
19
32
#define BUFFER_SIZE 512 // /< Size of the buffer
20
33
#define NL " \n "
21
34
22
- SoftwareSerial simSerial = SoftwareSerial(SIM_TX, SIM_RX) ;
35
+ SIM_SERIAL_TYPE simSerial = SIM_SERIAL ;
23
36
SIM808 sim808 = SIM808(SIM_RST, SIM_PWR, SIM_STATUS);
24
37
bool done = false ;
25
38
char buffer[BUFFER_SIZE];
@@ -31,36 +44,36 @@ void setup() {
31
44
simSerial.begin (SIM808_BAUDRATE);
32
45
sim808.begin (simSerial);
33
46
34
- Log.notice (F (" Powering on SIM808..." NL));
47
+ Log.notice (S_F (" Powering on SIM808..." NL));
35
48
sim808.powerOnOff (true );
36
49
sim808.init ();
37
50
38
51
sim808.getImei (buffer, BUFFER_SIZE);
39
- Log.notice (F (" IMEI : \" %s\" " NL), buffer);
52
+ Log.notice (S_F (" IMEI : \" %s\" " NL), buffer);
40
53
41
54
sim808.getSimState (buffer, BUFFER_SIZE);
42
- Log.notice (F (" SIM card state : \" %s\" " NL), buffer);
55
+ Log.notice (S_F (" SIM card state : \" %s\" " NL), buffer);
43
56
44
57
SIM808ChargingStatus charging = sim808.getChargingState ();
45
58
switch (charging.state ) {
46
- case SIM808_CHARGING_STATE::CHARGING :
47
- strcpy_P (buffer, PSTR (" CHARGING " ));
59
+ case SIM808ChargingState::Charging :
60
+ STRLCPY_P (buffer, PSTR (" Charging " ));
48
61
break ;
49
- case SIM808_CHARGING_STATE::CHARGING_DONE :
50
- strcpy_P (buffer, PSTR (" CHARGING_DONE " ));
62
+ case SIM808ChargingState::ChargingDone :
63
+ STRLCPY_P (buffer, PSTR (" ChargingDone " ));
51
64
break ;
52
- case SIM808_CHARGING_STATE::ERROR :
53
- strcpy_P (buffer, PSTR (" ERROR " ));
65
+ case SIM808ChargingState::Error :
66
+ STRLCPY_P (buffer, PSTR (" Error " ));
54
67
break ;
55
- case SIM808_CHARGING_STATE::NOT_CHARGING :
56
- strcpy_P (buffer, PSTR (" NOT_CHARGING " ));
68
+ case SIM808ChargingState::NotCharging :
69
+ STRLCPY_P (buffer, PSTR (" NotCharging " ));
57
70
break ;
58
71
}
59
- Log.notice (F (" Charging state : %s, %d%% @ %dmV" NL), buffer, charging.level , charging.voltage );
72
+ Log.notice (S_F (" Charging state : %s, %d%% @ %dmV" NL), buffer, charging.level , charging.voltage );
60
73
61
74
// you can also send unimplemented simple commands
62
75
sim808.sendCommand (" I" , buffer, BUFFER_SIZE);
63
- Log.notice (F (" ATI response : \" %s\" " NL), buffer);
76
+ Log.notice (S_F (" ATI response : \" %s\" " NL), buffer);
64
77
}
65
78
66
79
void loop () { }
0 commit comments