Closed Francois-37 closed 3 years ago
If everything works when it's plugged in to USB but not battery, it's probably a hardware problem related to whatever voltage regulator feeds power from the battery to the SIM7000. I don't know anything about that specific board, but I do know that if the SIM7000 isn't getting enough power it won't work. It might be able to communicate over the serial port but it won't connect to the internet. You'll have to take a hard look at the schematic and look at what regulators are feeding power where and how much load (amperage) they can handle. You might need a secondary battery or something. I suggest you look for help on the site or forum of whoever manufactured your board.
If you have a software issue with the library, please make a new issue for it!
When I am with the serial connexion everything work but on battery I haven't the return on dweet (with SSL). I haven't Solar panel, I dont know if it is the problem. The battery test is ok (64%, 3,84V) I haven't test because I haven't serial return. Sorry for my english, I'm french. Thank for your help
The code :
include
// Example program used while developing the SIM7000_CA module // Used with a "Lolin D32 pro" ESP32 board
/** *
// Select your modem:
define TINY_GSM_MODEM_SIM7000_CA
// #define TINY_GSM_MODEM_SIM808 // #define TINY_GSM_MODEM_SIM868 // #define TINY_GSM_MODEM_UBLOX // #define TINY_GSM_MODEM_SARAR4 // #define TINY_GSM_MODEM_ESP8266 // #define TINY_GSM_MODEM_XBEE // #define TINY_GSM_MODEM_SEQUANS_MONARCH
// Set serial for debug console (to the Serial Monitor, default speed 115200)
define SerialMon Serial
// Set serial for AT commands (to the module) // Use Hardware Serial on Mega, Leonardo, Micro
define SerialAT Serial1
include //lib I2C
// or Software Serial on Uno, Nano //#include
//SoftwareSerial SerialAT(2, 3); // RX, TX
// Increase RX buffer to capture the entire response // Chips without internal buffering (A6/A7, ESP8266, M590) // need enough space in the buffer for the entire response // else data will be lost (and the http library will fail).
if !defined(TINY_GSM_RX_BUFFER)
define TINY_GSM_RX_BUFFER 650
endif
// See all AT commands, if wanted
define DUMP_AT_COMMANDS
// Define the serial console for debug prints, if needed
define TINY_GSM_DEBUG SerialMon
// #define LOGGING // <- Logging is for the HTTP library
// Range to attempt to autobaud
define GSM_AUTOBAUD_MIN 9600
define GSM_AUTOBAUD_MAX 115200
// Add a reception delay - may be needed for a fast processor at a slow baud rate // #define TINY_GSM_YIELD() { delay(2); }
// Define how you're planning to connect to the internet
define TINY_GSM_USE_GPRS true
define TINY_GSM_USE_WIFI false
define TINY_GSM_POWERDOWN true
define TINY_GSM_TEST_BATTERY true
define uS_TO_S_FACTOR 1000000ULL // Conversion factor for micro seconds to seconds
define TIME_TO_SLEEP 60 // Time ESP32 will go to sleep (in seconds)
// set GSM PIN, if any
define GSM_PIN ""
// flag to force SSL client authentication, if needed // #define TINY_GSM_SSL_CLIENT_AUTHENTICATION
// Your GPRS credentials, if any const char apn[] = "orange.fr"; //SET TO YOUR APN const char gprsUser[] = "orange"; const char gprsPass[] = "orange";
// Your WiFi connection credentials, if applicable const char wifiSSID[] = "YourSSID"; const char wifiPass[] = "YourWiFiPass";
// Server details //const char server[] = "vsh.pp.ua"; //const char resource[] = "/TinyGSM/logo.txt";
//const char server[] = "qual.time.preditic.com"; const char server[] = "www.dweet.io"; //const char resource[] = "/api/v1/sensors/temperature/add?temperatureSensorApiToken=13d9620d4dcf329bb33675fc33f1699e2319f76bd46591c1d44402f15828201b"; //const char resource[] = "/dweet/for/MESEATHING?t=30"; const int port = 443; int stat_NetworkStatus = 0; int nombre_iteration_avant_redemarrage=5; int i=0; //en attendant la temparture float temperature=0; int delay_2_envois=5000;
include
include
const int oneWireBus = 0;
OneWire oneWire(oneWireBus); DallasTemperature sensors(&oneWire);
include
include
// Just in case someone defined the wrong thing..
if TINY_GSM_USE_GPRS && not defined TINY_GSM_MODEM_HAS_GPRS
undef TINY_GSM_USE_GPRS
undef TINY_GSM_USE_WIFI
define TINY_GSM_USE_GPRS false
define TINY_GSM_USE_WIFI true
endif
if TINY_GSM_USE_WIFI && not defined TINY_GSM_MODEM_HAS_WIFI
undef TINY_GSM_USE_GPRS
undef TINY_GSM_USE_WIFI
define TINY_GSM_USE_GPRS true
define TINY_GSM_USE_WIFI false
endif
ifdef DUMP_AT_COMMANDS
include
StreamDebugger debugger(SerialAT, SerialMon); TinyGsm modem(debugger);
else
TinyGsm modem(SerialAT);
endif
TinyGsmClientSecure client(modem); HttpClient http(client, server, port);
void setup() { // Set console baud rate //--SerialMon.begin(115200); Serial.begin(9600); delay(10);
// Set LED OFF pinMode(12, OUTPUT); digitalWrite(12, HIGH);
pinMode(4, OUTPUT); digitalWrite(4, HIGH); delay(300); digitalWrite(4, LOW);
// !!!!!!!!!!! // Set your reset, enable, power pins here // !!!!!!!!!!!
SerialMon.println("Wait...");
delay(10000);
// Set GSM module baud rate //TinyGsmAutoBaud(SerialAT, GSM_AUTOBAUD_MIN, GSM_AUTOBAUD_MAX); //--SerialAT.begin(115200, SERIAL_8N1, 26, 25); SerialAT.begin(9600, SERIAL_8N1, 26, 27); delay(6000);
// Restart takes quite some time // To skip it, call init() instead of restart() SerialMon.println("Initializing modem..."); if (!modem.restart()) { Serial.println("Failed to restart modem"); stat_NetworkStatus=-1; } // modem.init();
String name = modem.getModemName(); delay(500); Serial.println("Modem Name: " + name);
String modemInfo = modem.getModemInfo(); delay(500); Serial.println("Modem Info: " + modemInfo);
if TINY_GSM_USE_GPRS
// Unlock your SIM card with a PIN if needed if ( GSM_PIN && modem.getSimStatus() != 3 ) { modem.simUnlock(GSM_PIN); }
endif
sensors.begin(); }
void loop() {
if(stat_NetworkStatus== -1 || stat_NetworkStatus> nombre_iteration_avant_redemarrage) { Serial.println("Restarting !"); ESP.restart(); }
sensors.requestTemperatures(); float temperatureC = sensors.getTempCByIndex(0); Serial.print(temperatureC); Serial.println("ºC");
if TINY_GSM_TEST_BATTERY
uint8_t chargeState = -99; int8_t percent = -99; uint16_t milliVolts = -9999; modem.getBattStats(chargeState, percent, milliVolts); DBG("Battery charge state:", chargeState); DBG("Battery charge 'percent':", percent); DBG("Battery voltage:", milliVolts / 1000.0F);
endif
//while(1);
char resource[50];// = "/dweet/for/MESEATHING?t=30"; sprintf(resource, "/dweet/for/MESEATHING?t=%.1f&percent=%d", temperatureC, percent);
if TINY_GSM_USE_WIFI
// Wifi connection parameters must be set before waiting for the network SerialMon.print(F("Setting SSID/password...")); if (!modem.networkConnect(wifiSSID, wifiPass)) { SerialMon.println(" fail"); delay(10000); return; } SerialMon.println(" success");
endif
if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_XBEE
// The XBee must run the gprsConnect function BEFORE waiting for network! modem.gprsConnect(apn, gprsUser, gprsPass);
endif
SerialMon.print("Waiting for network..."); if (!modem.waitForNetwork()) { SerialMon.println(" fail"); delay(10000); return; } SerialMon.println(" success");
if (modem.isNetworkConnected()) { SerialMon.println("Network connected"); }
if TINY_GSM_USE_GPRS
// GPRS connection parameters are usually set after network registration SerialMon.print(F("Connecting to ")); SerialMon.print(apn); if (!modem.gprsConnect(apn, gprsUser, gprsPass)) { SerialMon.println(" fail"); delay(10000); stat_NetworkStatus++; //return; } SerialMon.println(" success");
endif
SerialMon.print(F("Performing HTTPS GET request... ")); http.connectionKeepAlive(); // Currently, this is needed for HTTPS int err = http.get(resource); if (err != 0) { SerialMon.println(F("failed to connect")); delay(10000); stat_NetworkStatus++; //return; }
int status = http.responseStatusCode(); SerialMon.print(F("Response status code: ")); SerialMon.println(status); if (!status) { delay(10000); stat_NetworkStatus++; //return; }
// SerialMon.println(F("Response Headers:")); // while (http.headerAvailable()) { // String headerName = http.readHeaderName(); // String headerValue = http.readHeaderValue(); // SerialMon.println(" " + headerName + " : " + headerValue); // } // // int length = http.contentLength(); // if (length >= 0) { // SerialMon.print(F("Content length is: ")); // SerialMon.println(length); // } // if (http.isResponseChunked()) { // SerialMon.println(F("The response is chunked")); // } // // String body = http.responseBody(); // SerialMon.println(F("Response:")); // SerialMon.println(body); // // SerialMon.print(F("Body length is: ")); // SerialMon.println(body.length());
// Shutdown
http.stop(); SerialMon.println(F("Server disconnected"));
if TINY_GSM_USE_WIFI
endif
if TINY_GSM_USE_GPRS
endif
// Do nothing forevermore //while (true) delay(1000);
delay(delay_2_envois);
if TINY_GSM_POWERDOWN
// Try to power-off (modem may decide to restart automatically) // To turn off modem completely, please use Reset/Enable pins modem.poweroff(); Serial.println("Poweroff.");
endif
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); delay(200); esp_deep_sleep_start();
// Do nothing forevermore while (true) { modem.maintain(); }
}