Skip to content

Commit d99de04

Browse files
authored
Merge pull request #7 from blemasle/features-esp32-compatibility
Platforms compatibitily enhancements
2 parents 5e6f868 + 979db7d commit d99de04

File tree

17 files changed

+404
-305
lines changed

17 files changed

+404
-305
lines changed

.travis.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ language: c
22
env:
33
global:
44
- ARDUINO_IDE_VERSION="1.8.5"
5+
- ARDUINO_ESP32_VERSION="1.0.1"
56
- LIBRARY_NAME="SIM808"
7+
matrix:
8+
- ESP32=false BOARD="arduino:avr:uno"
9+
- ESP32=true BOARD="esp32:esp32:pico32"
610
before_install:
711
- "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16"
812
- sleep 3
@@ -11,14 +15,16 @@ before_install:
1115
- tar xf arduino-$ARDUINO_IDE_VERSION-linux64.tar.xz
1216
- sudo mv arduino-$ARDUINO_IDE_VERSION /usr/local/share/arduino
1317
- sudo ln -s /usr/local/share/arduino/arduino /usr/local/bin/arduino
18+
- arduino --pref boardsmanager.additional.urls=https://dl.espressif.com/dl/package_esp32_index.json --save-prefs
19+
- if $ESP32; then arduino --install-boards esp32:esp32:$ARDUINO_ESP32_VERSION; fi
1420
install:
1521
- ln -s $PWD /usr/local/share/arduino/libraries/$LIBRARY_NAME
1622
- arduino --install-library "ArduinoLog"
1723
script:
18-
- arduino --verify --board arduino:avr:uno $PWD/examples/AcquireGPSPosition/AcquireGPSPosition.ino
19-
- arduino --verify --board arduino:avr:uno $PWD/examples/GeneralInformation/GeneralInformation.ino
20-
- arduino --verify --board arduino:avr:uno $PWD/examples/HttpPost/HttpPost.ino
21-
- arduino --verify --board arduino:avr:uno $PWD/examples/Tester/Tester.ino
24+
- arduino --verify --board $BOARD $PWD/examples/AcquireGPSPosition/AcquireGPSPosition.ino
25+
- arduino --verify --board $BOARD $PWD/examples/GeneralInformation/GeneralInformation.ino
26+
- arduino --verify --board $BOARD $PWD/examples/HttpPost/HttpPost.ino
27+
- arduino --verify --board $BOARD $PWD/examples/Tester/Tester.ino
2228
notifications:
2329
email:
2430
on_success: change

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ It does *not* have the pretention to become the new SIM808 standard library, but
4444

4545
#define SIM808_BAUDRATE 4800 ///< Control the baudrate use to communicate with the SIM808 module
4646

47-
SoftwareSerial simSerial = SoftwareSerial(SIM_TX, SIM_RX)
47+
SoftwareSerial simSerial = SoftwareSerial(SIM_TX, SIM_RX);
4848
SIM808 sim808 = SIM808(SIM_RST, SIM_PWR, SIM_STATUS);
4949
// SIM808 sim808 = SIM808(SIM_RST); // if you only have the RESET pin wired
5050
// SIM808 sim808 = SIM808(SIM_RST, SIM_PWR); // if you only have the RESET and PWRKEY pins wired

examples/AcquireGPSPosition/AcquireGPSPosition.ino

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@
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+
#else
13+
#include <HardwareSerial.h>
14+
#define SIM_SERIAL_TYPE HardwareSerial ///< Type of variable that holds the Serial communication with SIM808
15+
#define SIM_SERIAL SIM_SERIAL_TYPE(2) ///< Definition of the instance that holds the Serial communication with SIM808
16+
#endif
817

918
#define SIM_RST 5 ///< SIM808 RESET
1019
#define SIM_RX 6 ///< SIM808 RXD
@@ -20,7 +29,13 @@
2029
#define POSITION_SIZE 128 ///< Size of the position buffer
2130
#define NL "\n"
2231

23-
SoftwareSerial simSerial = SoftwareSerial(SIM_TX, SIM_RX);
32+
#if defined(__AVR__)
33+
typedef __FlashStringHelper* __StrPtr;
34+
#else
35+
typedef const char* __StrPtr;
36+
#endif
37+
38+
SIM_SERIAL_TYPE simSerial = SIM_SERIAL;
2439
SIM808 sim808 = SIM808(SIM_RST, SIM_PWR, SIM_STATUS);
2540
char position[POSITION_SIZE];
2641

@@ -31,39 +46,39 @@ void setup() {
3146
simSerial.begin(SIM808_BAUDRATE);
3247
sim808.begin(simSerial);
3348

34-
Log.notice(F("Powering on SIM808..." NL));
49+
Log.notice(S_F("Powering on SIM808..." NL));
3550
sim808.powerOnOff(true);
3651
sim808.init();
3752

38-
Log.notice(F("Powering on SIM808's GPS..." NL));
53+
Log.notice(S_F("Powering on SIM808's GPS..." NL));
3954
sim808.powerOnOffGps(true);
4055
}
4156

4257
void loop() {
43-
SIM808_GPS_STATUS status = sim808.getGpsStatus(position, POSITION_SIZE);
58+
SIM808GpsStatus status = sim808.getGpsStatus(position, POSITION_SIZE);
4459

45-
if(status < SIM808_GPS_STATUS::FIX) {
46-
Log.notice(F("No fix yet..." NL));
60+
if(status < SIM808GpsStatus::Fix) {
61+
Log.notice(S_F("No fix yet..." NL));
4762
delay(NO_FIX_GPS_DELAY);
4863
return;
4964
}
5065

5166
uint16_t sattelites;
5267
float lat, lon;
53-
__FlashStringHelper * state;
68+
__StrPtr state;
5469

55-
if(status == SIM808_GPS_STATUS::FIX) state = S_F("Normal");
70+
if(status == SIM808GpsStatus::Fix) state = S_F("Normal");
5671
else state = S_F("Accurate");
5772

58-
sim808.getGpsField(position, SIM808_GPS_FIELD::GNSS_USED, &sattelites);
59-
sim808.getGpsField(position, SIM808_GPS_FIELD::LATITUDE, &lat);
60-
sim808.getGpsField(position, SIM808_GPS_FIELD::LONGITUDE, &lon);
73+
sim808.getGpsField(position, SIM808GpsField::GnssUsed, &sattelites);
74+
sim808.getGpsField(position, SIM808GpsField::Latitude, &lat);
75+
sim808.getGpsField(position, SIM808GpsField::Longitude, &lon);
6176

62-
Log.notice(F("%s" NL), position);
63-
Log.notice(F("Fix type: %S" NL), state);
64-
Log.notice(F("Sattelites used : %d" NL), sattelites);
65-
Log.notice(F("Latitude : %F" NL), lat);
66-
Log.notice(F("Longitude : %F" NL), lon);
77+
Log.notice(S_F("%s" NL), position);
78+
Log.notice(S_F("Fix type: %S" NL), state);
79+
Log.notice(S_F("Sattelites used : %d" NL), sattelites);
80+
Log.notice(S_F("Latitude : %F" NL), lat);
81+
Log.notice(S_F("Longitude : %F" NL), lon);
6782

6883
delay(FIX_GPS_DELAY);
6984
}

examples/GeneralInformation/GeneralInformation.ino

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,20 @@
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
@@ -19,7 +32,7 @@
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;
2336
SIM808 sim808 = SIM808(SIM_RST, SIM_PWR, SIM_STATUS);
2437
bool done = false;
2538
char 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

6679
void loop() { }

examples/HttpPost/HttpPost.ino

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,20 @@
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
@@ -23,7 +36,7 @@
2336
#define BUFFER_SIZE 512 ///< Side of the response buffer
2437
#define NL "\n"
2538

26-
SoftwareSerial simSerial = SoftwareSerial(SIM_TX, SIM_RX);
39+
SIM_SERIAL_TYPE simSerial = SIM_SERIAL;
2740
SIM808 sim808 = SIM808(SIM_RST, SIM_PWR, SIM_STATUS);
2841
bool done = false;
2942
char buffer[BUFFER_SIZE];
@@ -35,7 +48,7 @@ void setup() {
3548
simSerial.begin(SIM808_BAUDRATE);
3649
sim808.begin(simSerial);
3750

38-
Log.notice(F("Powering on SIM808..." NL));
51+
Log.notice(S_F("Powering on SIM808..." NL));
3952
sim808.powerOnOff(true);
4053
sim808.init();
4154
}
@@ -46,34 +59,34 @@ void loop() {
4659
return;
4760
}
4861

49-
SIM808_NETWORK_REGISTRATION_STATE status = sim808.getNetworkRegistrationStatus();
62+
SIM808NetworkRegistrationState status = sim808.getNetworkRegistrationStatus();
5063
SIM808SignalQualityReport report = sim808.getSignalQuality();
5164

5265
bool isAvailable = static_cast<int8_t>(status) &
53-
(static_cast<int8_t>(SIM808_NETWORK_REGISTRATION_STATE::REGISTERED) | static_cast<int8_t>(SIM808_NETWORK_REGISTRATION_STATE::ROAMING))
66+
(static_cast<int8_t>(SIM808NetworkRegistrationState::Registered) | static_cast<int8_t>(SIM808NetworkRegistrationState::Roaming))
5467
!= 0;
5568

5669
if(!isAvailable) {
57-
Log.notice(F("No network yet..." NL));
70+
Log.notice(S_F("No network yet..." NL));
5871
delay(NETWORK_DELAY);
5972
return;
6073
}
6174

62-
Log.notice(F("Network is ready." NL));
63-
Log.notice(F("Attenuation : %d dBm, Estimated quality : %d" NL), report.attenuation, report.rssi);
75+
Log.notice(S_F("Network is ready." NL));
76+
Log.notice(S_F("Attenuation : %d dBm, Estimated quality : %d" NL), report.attenuation, report.rssi);
6477

6578
bool enabled = false;
6679
do {
67-
Log.notice(F("Powering on SIM808's GPRS..." NL));
80+
Log.notice(S_F("Powering on SIM808's GPRS..." NL));
6881
enabled = sim808.enableGprs(GPRS_APN, GPRS_USER, GPRS_PASS);
6982
} while(!enabled);
7083

71-
Log.notice(F("Sending HTTP request..." NL));
72-
strncpy_P(buffer, PSTR("This is the body"), BUFFER_SIZE);
84+
Log.notice(S_F("Sending HTTP request..." NL));
85+
STRLCPY_P(buffer, PSTR("This is the body"));
7386
//notice that we're using the same buffer for both body and response
74-
uint16_t responseCode = sim808.httpPost("http://httpbin.org/anything", F("text/plain"), buffer, buffer, BUFFER_SIZE);
87+
uint16_t responseCode = sim808.httpPost("http://httpbin.org/anything", S_F("text/plain"), buffer, buffer, BUFFER_SIZE);
7588

76-
Log.notice(F("Server responsed : %d" NL), responseCode);
89+
Log.notice(S_F("Server responsed : %d" NL), responseCode);
7790
Log.notice(buffer);
7891

7992
done = true;

0 commit comments

Comments
 (0)