Giter Site home page Giter Site logo

ESP32 error about arduino-sim808 HOT 11 CLOSED

DaveCalaway avatar DaveCalaway commented on August 15, 2024
ESP32 error

from arduino-sim808.

Comments (11)

blemasle avatar blemasle commented on August 15, 2024 1

It was 2am and I miss read the compiler output. The issue is related to DISABLED being a preprocessor directive, so the enum class declaration is no longer valid once the preprocessor has done its job.

I'll see what I can do to change the names that can conflict with standard #define.

from arduino-sim808.

blemasle avatar blemasle commented on August 15, 2024

Hi Dave,

I'm not familiar with ESP32 boards but I can reproduce the same compilation error after choosing one of the esp32:esp32:pico32 board for instance.

To me it looks like enum class are just treated as enum, which leads to name conflicts. It has nothing to do with the library itself, and could be reproduced with a simple sketch as this one.

#include <Arduino.h>

enum class toto_t {
    DISABLED = 5
};

void setup() {

}

void loop() {

}

enum class are parts of C++ 11, but the compiler does seems to use that version (if you enable verbose log you can see -std=gnu++11 amongs the used flags). For the moment I have no clue how to solve this :/

from arduino-sim808.

blemasle avatar blemasle commented on August 15, 2024

Sorry for the delay @DaveCalaway, I've been busy the past few days. Would you be kind enough to try the associated PR #7 and test/review it ?

It builds fine on my side but without the hardware at hand, I cannot test it for real 😃

from arduino-sim808.

DaveCalaway avatar DaveCalaway commented on August 15, 2024

@blemasle sure.
I'm sorry but my esp32 is blowed up today in another test, so i try only this fast example on another esp32.

This is my platformio.ini file for this test, over the features-esp32-compatibility branch:

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
upload_speed = 115200

lib_deps =
  ;SIM808
  https://github.com/blemasle/arduino-sim808.git#features-esp32-compatibility
  ArduinoLog

Code:

/*
   Example for ESP32
 */
#include <Arduino.h>
#include <SIM808.h>

#define SIM_RST   4 ///< SIM808 RESET
// Optional pins
// #define SIM_PWR   9 ///< SIM808 PWRKEY
//#define SIM_STATUS  8 ///< SIM808 STATUS

#define SIM808_BAUDRATE  38400   ///< Control the baudrate use to communicate with the SIM808 module
#define SERIAL_BAUDRATE 115200   ///< Controls the serial baudrate between the arduino and the computer
#define _DEBUG 1 // Enable the debug

HardwareSerial simSerial(2); // ESP32 second HW UART 16 = RX - 17 = TX
SIM808 sim808 = SIM808(SIM_RST); // if you only have the RESET pin wired
//SIM808 sim808 = SIM808(SIM_RST, SIM_PWR, SIM_STATUS);
// SIM808 sim808 = SIM808(SIM_RST, SIM_PWR); // if you only have the RESET and PWRKEY pins wired

void setup() {
        // Serial from ESP32 to PC
        Serial.begin(SERIAL_BAUDRATE);
        Log.begin(LOG_LEVEL_NOTICE, &Serial);

        // Serial from ESP32 to SIM808
        simSerial.begin(SIM808_BAUDRATE);
        sim808.begin(simSerial);

        //Log.notice(F("Powering on SIM808..." NL));

        sim808.powerOnOff(true); //power on the SIM808. Unavailable without the PWRKEY pin wired
        sim808.init();
}

void loop() {
        // whatever you need to do
}

It's build fine. Tomorrow i will load it and see what it do.

If i uncomment the line:
Log.notice(F("Powering on SIM808..." NL));
it gives me this error:

In file included from /Users/dave/.platformio/packages/framework-arduinoespressif32/cores/esp32/WString.h:29:0,
from /Users/dave/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:152,
from src/main.cpp:4:
src/main.cpp: In function 'void setup()':
src/main.cpp:30:46: error: expected ')' before 'NL'
Log.notice(F("Powering on SIM808..." NL));
^
Users/dave/.platformio/packages/framework-arduinoespressif32/cores/esp32/pgmspace.h:36:24: note: in definition of macro 'PSTR'
#define PSTR(s)       (s)
^
src/main.cpp:30:20: note: in expansion of macro 'F'
Log.notice(F("Powering on SIM808..." NL));
^
src/main.cpp:30:50: error: expected ')' before ';' token
Log.notice(F("Powering on SIM808..." NL));
^
src/main.cpp:30:50: error: expected ')' before ';' token
src/main.cpp:30:50: error: expected ')' before ';' token
*** [.pioenvs/esp32dev/src/main.cpp.o] Error 1

Extra info:
in the README.md, in main page, is missing a ";" in the line "SoftwareSerial simSerial = SoftwareSerial(SIM_TX, SIM_RX)" ?

from arduino-sim808.

blemasle avatar blemasle commented on August 15, 2024

You're absolutely right about the missing semicolon. Thanks !

Regarding the Log.notice line, you're missing the #define NL "\n" found in other examples.
There are some other issues though with the flash stored strings in the library. I'll try to fix these before merging the PR.

In the meantime, just adding the define above should be enough to make your sketch work.

from arduino-sim808.

DaveCalaway avatar DaveCalaway commented on August 15, 2024

My board, not has the PWRKEY pin exposed. It start with a button called PWD.
I need to reset the ESP32 and the 808 at the same time to stat the connection during the "sim808.begin".
Or, better, omit that function.

/*
   Example for ESP32
 */
#include <Arduino.h>
#include <SIM808.h>

#define SIM_RST   4 ///< SIM808 RESET
// Optional pins
//#define SIM_PWR   5 ///< SIM808 PWRKEY
#define SIM_STATUS  18 ///< SIM808 STATUS

#define SIM808_BAUDRATE  38400   ///< Control the baudrate use to communicate with the SIM808 module
#define SERIAL_BAUDRATE 115200   ///< Controls the serial baudrate between the arduino and the computer
#define BUFFER_SIZE 512         ///< Size of the buffer
#define NETWORK_DELAY  10000    ///< Delay between each GPS read
#define _DEBUG 1 // Enable the debug
#define NL "\n"

HardwareSerial simSerial(2); // ESP32 second HW UART 16 = RX - 17 = TX
SIM808 sim808 = SIM808(SIM_RST); // if you only have the RESET pin wired
//SIM808 sim808 = SIM808(SIM_RST, SIM_PWR, SIM_STATUS);
// SIM808 sim808 = SIM808(SIM_RST, SIM_PWR); // if you only have the RESET and PWRKEY pins wired
bool done = false;
char buffer[BUFFER_SIZE];

void setup() {
        // Serial from ESP32 to PC
        Serial.begin(SERIAL_BAUDRATE);
        Log.begin(LOG_LEVEL_NOTICE, &Serial);

        Serial.begin(SERIAL_BAUDRATE);
        Log.begin(LOG_LEVEL_NOTICE, &Serial);

        simSerial.begin(SIM808_BAUDRATE);
        sim808.begin(simSerial);

        //Log.notice(F("Powering on SIM808..." NL));
        //sim808.powerOnOff(true);
        //sim808.init();
        Log.notice(F("Go SIM808..." NL));

        sim808.getImei(buffer, BUFFER_SIZE);
        Log.notice(F("IMEI : \"%s\"" NL), buffer);

        sim808.getSimState(buffer, BUFFER_SIZE);
        Log.notice(F("SIM card state : \"%s\"" NL), buffer);

        SIM808ChargingStatus charging = sim808.getChargingState();
        switch(charging.state) {
        case SIM808_CHARGING_STATE::CHARGING:
                strcpy_P(buffer, PSTR("CHARGING"));
                break;
        case SIM808_CHARGING_STATE::CHARGING_DONE:
                strcpy_P(buffer, PSTR("CHARGING_DONE"));
                break;
        case SIM808_CHARGING_STATE::ERROR:
                strcpy_P(buffer, PSTR("ERROR"));
                break;
        case SIM808_CHARGING_STATE::NOT_CHARGING:
                strcpy_P(buffer, PSTR("NOT_CHARGING"));
                break;
        }
        Log.notice(F("Charging state : %s, %d%% @ %dmV" NL), buffer, charging.level, charging.voltage);

        //you can also send unimplemented simple commands
        sim808.sendCommand("I", buffer, BUFFER_SIZE);
        Log.notice(F("ATI response : \"%s\"" NL), buffer);

}

void loop() {
        // whatever you need to do
}

Output

N: Go SIM808...
": IMEI : "865067020808575
": SIM card state : "865067020808575
N: Charging state : NOT_CHARGING, 61% @ 3892mV
N: ATI response : "
SIM808 R14.18

OK

+CPIN: READY

I think it's looks good.

So i decided to move in to the GPS example:

/*
   Example for ESP32
 */
#include <Arduino.h>
#include <SIM808.h>

#define SIM_RST   4 ///< SIM808 RESET
// Optional pins
//#define SIM_PWR   5 ///< SIM808 PWRKEY
#define SIM_STATUS  18 ///< SIM808 STATUS

#define SIM808_BAUDRATE  38400   ///< Control the baudrate use to communicate with the SIM808 module
#define SERIAL_BAUDRATE 115200   ///< Controls the serial baudrate between the arduino and the computer
#define POSITION_SIZE 512         ///< Size of the buffer
#define NO_FIX_GPS_DELAY 3000   ///< Delay between each GPS read when no fix is acquired
#define FIX_GPS_DELAY  10000    ///< Delay between each GPS read when a fix is acquired
#define _DEBUG 1 // Enable the debug
#define NL "\n"

HardwareSerial simSerial(2); // ESP32 second HW UART 16 = RX - 17 = TX
SIM808 sim808 = SIM808(SIM_RST); // if you only have the RESET pin wired
//SIM808 sim808 = SIM808(SIM_RST, SIM_PWR, SIM_STATUS);
// SIM808 sim808 = SIM808(SIM_RST, SIM_PWR); // if you only have the RESET and PWRKEY pins wired
bool done = false;
char buffer[BUFFER_SIZE];
char position[POSITION_SIZE];

void setup() {
        // Serial from ESP32 to PC
        Serial.begin(SERIAL_BAUDRATE);
        Log.begin(LOG_LEVEL_NOTICE, &Serial);

        Serial.begin(SERIAL_BAUDRATE);
        Log.begin(LOG_LEVEL_NOTICE, &Serial);

        simSerial.begin(SIM808_BAUDRATE);
        sim808.begin(simSerial);

        //Log.notice(F("Powering on SIM808..." NL));
        //sim808.powerOnOff(true);
        Log.notice(F("Go SIM808..." NL));
        sim808.init();

        Log.notice(F("Powering on SIM808's GPS..." NL));
        sim808.powerOnOffGps(true);
}

void loop() {
        SIM808_GPS_STATUS status = sim808.getGpsStatus(position, POSITION_SIZE);

        if(status < SIM808_GPS_STATUS::FIX) {
                Log.notice(F("No fix yet..." NL));
                delay(NO_FIX_GPS_DELAY);
                return;
        }

        uint16_t sattelites;
        float lat, lon;
        __FlashStringHelper * state;

        if(status == SIM808_GPS_STATUS::FIX) state = S_F("Normal");
        else state = S_F("Accurate");

        sim808.getGpsField(position, SIM808_GPS_FIELD::GNSS_USED, &sattelites);
        sim808.getGpsField(position, SIM808_GPS_FIELD::LATITUDE, &lat);
        sim808.getGpsField(position, SIM808_GPS_FIELD::LONGITUDE, &lon);

        Log.notice(F("%s" NL), position);
        Log.notice(F("Fix type: %S" NL), state);
        Log.notice(F("Sattelites used : %d" NL), sattelites);
        Log.notice(F("Latitude : %F" NL), lat);
        Log.notice(F("Longitude : %F" NL), lon);

        delay(FIX_GPS_DELAY);
}

But i have those errors:

src/main.cpp: In function 'void loop()':
src/main.cpp:61:52: error: cannot convert 'const char [7]' to '__FlashStringHelper*' in assignment
if(status == SIM808_GPS_STATUS::FIX) state = S_F("Normal");
^
src/main.cpp:62:20: error: cannot convert 'const char [9]' to '__FlashStringHelper*' in assignment
else state = S_F("Accurate");

I suppose that the problem is in those lines:

#if defined(__AVR__)
    typedef const __FlashStringHelper* ATConstStr;

    #define S_PROGMEM PROGMEM
    #define S_F(x)   F(x)
    #define TO_F(x) (reinterpret_cast<ATConstStr>(x))
    #define TO_P(x) (reinterpret_cast<const char*>(x))
#else
    typedef const char* ATConstStr;

    #define S_PROGMEM
    #define S_F(x)   x
    #define TO_F(x) x
    #define TO_P(x) x
#endif

from arduino-sim808.

blemasle avatar blemasle commented on August 15, 2024

Without the sim808.init(); call, you're taking the risk that your SIM808 is not properly set up for communication with the library.

Regarding your issue with __FlashStringHelper, these are one of the issues I talked about earlier. I'm trying to find a way for all the examples and the library to work on platforms without PROGMEM support. I'm honestly not sure how to achieve this properly as I'm using flash stored string to format AT messages in the library itself. I would be curious to see how such formats work at the moment (for instance the setSmsMessageFormat function).

For the moment you can replace the __FlashStringHelper * variables declaration with char *, it should do the trick.

from arduino-sim808.

blemasle avatar blemasle commented on August 15, 2024

So.
I changed the examples to build on all platforms. Again, I'm not able to test these changes for real so I'll be grateful if you could tell me if it's all working out for you.

And also how the flash formatted AT messages behave on your platform (does the setSmsMessageFormat works correctly for instance ?)

from arduino-sim808.

DaveCalaway avatar DaveCalaway commented on August 15, 2024

Without the sim808.init(); call, you're taking the risk that your SIM808 is not properly set up for communication with the library.

For now i checked the speed for the serial manually.

For the moment you can replace the __FlashStringHelper * variables declaration with char *, it should do the trick.

Good it works perfectly.

I did not test the "setSmsMessageFormat", do you have an example that i can try?

from arduino-sim808.

blemasle avatar blemasle commented on August 15, 2024

I did not test the "setSmsMessageFormat", do you have an example that i can try?

Just force _SIM808_DEBUG to 1 in SIMComAT.h to enable debug print and add the following lines to one of your sketch

   sim808.setEcho(SIM808Echo::On);
   sim808.setSmsMessageFormat(SIM808SmsMessageFormat::Text);
   sim808.setEcho(SIM808Echo::Off);

Then could you please paste here the resulting log ? Be aware that I used the renamed enums (last commits on #7 ) but in case your still using the old version, here you go

   sim808.setEcho(SIM808_ECHO::ON);
   sim808.setSmsMessageFormat(SIM808_SMS_MESSAGE_FORMAT::TEXT);
   sim808.setEcho(SIM808_ECHO::OFF);

I know the renaming can be painful but I had to do it in order to clear the original issue once and for all. Using all caps enums was a bad idea in the first place :/

Thanks !

from arduino-sim808.

blemasle avatar blemasle commented on August 15, 2024

Without news from @DaveCalaway , I'm going to merge those changes into master soon. Please gives me a heads up if you just didn't have the time to look at it or if you moved on to something else.

Thanks !

from arduino-sim808.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.