44
55#include < SIM808.h>
66#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
821
922#define SIM_RST 5 // /< SIM808 RESET
1023#define SIM_RX 6 // /< SIM808 RXD
1932#define BUFFER_SIZE 512 // /< Size of the buffer
2033#define NL " \n "
2134
22- SoftwareSerial simSerial = SoftwareSerial(SIM_TX, SIM_RX) ;
35+ SIM_SERIAL_TYPE simSerial = SIM_SERIAL ;
2336SIM808 sim808 = SIM808(SIM_RST, SIM_PWR, SIM_STATUS);
2437bool done = false ;
2538char buffer[BUFFER_SIZE];
@@ -31,36 +44,36 @@ void setup() {
3144 simSerial.begin (SIM808_BAUDRATE);
3245 sim808.begin (simSerial);
3346
34- Log.notice (F (" Powering on SIM808..." NL));
47+ Log.notice (S_F (" Powering on SIM808..." NL));
3548 sim808.powerOnOff (true );
3649 sim808.init ();
3750
3851 sim808.getImei (buffer, BUFFER_SIZE);
39- Log.notice (F (" IMEI : \" %s\" " NL), buffer);
52+ Log.notice (S_F (" IMEI : \" %s\" " NL), buffer);
4053
4154 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);
4356
4457 SIM808ChargingStatus charging = sim808.getChargingState ();
4558 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 " ));
4861 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 " ));
5164 break ;
52- case SIM808_CHARGING_STATE::ERROR :
53- strcpy_P (buffer, PSTR (" ERROR " ));
65+ case SIM808ChargingState::Error :
66+ STRLCPY_P (buffer, PSTR (" Error " ));
5467 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 " ));
5770 break ;
5871 }
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 );
6073
6174 // you can also send unimplemented simple commands
6275 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);
6477}
6578
6679void loop () { }
0 commit comments