** Good day I have an error when sending data from the laser rangefinder I tried to use the library Adafruit_VL53L0X.h but it seems that the library SIM800l and Adafruit_VL53L0X.h conflicts because of this I connected the sensor without the library but still comes out error 702 but if you remove the laser rangefinder everything works with dht11.
if you know how to solve the problem please help **
#include <Wire.h>
#include <SoftwareSerial.h>
#include "SIM800L.h"
#include <DHT.h>
#define SIM800_RX_PIN 8
#define SIM800_TX_PIN 9
#define SIM800_RST_PIN 4
#define DHT_PIN 3
#define DHT_TYPE DHT11
DHT dht(DHT_PIN, DHT_TYPE);
const char APN[] = "internet";
const char URL[] = "############";
SIM800L* sim800l;
#define VL53L0X_ADDRESS 0x29
void setup() {
dht.begin();
Serial.begin(115200);
while (!Serial);
Wire.begin(); // Initialize I²C
Wire.setClock(400000); // Set I²C clock to 400kHz
SoftwareSerial* serial = new SoftwareSerial(SIM800_RX_PIN, SIM800_TX_PIN);
serial->begin(9600);
delay(1000);
sim800l = new SIM800L((Stream *)serial, SIM800_RST_PIN, 200, 512);
setupModule();
}
void loop() {
performHttpGetRequest();
bool lowPowerMode = sim800l->setPowerMode(MINIMUM);
if (lowPowerMode) {
Serial.println(F("Module in low power mode"));
} else {
Serial.println(F("Failed to switch module to low power mode"));
}
delay(600000); // Delay for 10 minutes
bool normalPowerMode = sim800l->setPowerMode(NORMAL);
if (normalPowerMode) {
Serial.println(F("Module in normal power mode"));
} else {
Serial.println(F("Failed to switch module to normal power mode"));
}
}
void performHttpGetRequest() {
bool connected = false;
for (uint8_t i = 0; i < 100 && !connected; i++) {
delay(3000);
connected = sim800l->connectGPRS();
}
if (connected) {
Serial.print(F("GPRS connected with IP "));
Serial.println(sim800l->getIP());
Serial.println(sim800l->getSignal());
} else {
Serial.println(F("GPRS not connected!"));
Serial.println(F("Resetting the module."));
sim800l->reset();
setupModule();
return;
}
Serial.println(F("Start HTTP GET..."));
int dhtTemperature = dht.readTemperature();
uint16_t vlDistance = readVL53L0X();
String fullUrl = String(URL) + String(dhtTemperature) + String(vlDistance);
Serial.print(F("Temperature: "));
Serial.println(dhtTemperature);
Serial.print(F("Distance: "));
Serial.println(vlDistance);
uint16_t rc = sim800l->doGet(fullUrl.c_str(), 18000);
if (rc == 200) {
Serial.print(F("HTTP GET successful ("));
Serial.print(sim800l->getDataSizeReceived());
Serial.println(F(" bytes)"));
Serial.print(F("Received: "));
Serial.println(sim800l->getDataReceived());
} else {
Serial.print(F("HTTP GET error "));
Serial.println(rc);
}
delay(1000);
bool disconnected = sim800l->disconnectGPRS();
for (uint8_t i = 0; i < 5 && !disconnected; i++) {
delay(1000);
disconnected = sim800l->disconnectGPRS();
}
if (disconnected) {
Serial.println(F("GPRS disconnected!"));
} else {
Serial.println(F("GPRS still connected!"));
}
}
void setupModule() {
while (!sim800l->isReady()) {
Serial.println(F("Problem initializing AT command, retrying in 5 sec"));
delay(5000);
}
Serial.println(F("Module is ready"));
uint8_t signal = sim800l->getSignal();
while (signal <= 0) {
delay(1000);
signal = sim800l->getSignal();
}
Serial.print(F("Signal OK (strength: "));
Serial.print(signal);
Serial.println(F(")"));
delay(1000);
NetworkRegistration network = sim800l->getRegistrationStatus();
while (network != REGISTERED_HOME && network != REGISTERED_ROAMING) {
delay(1000);
network = sim800l->getRegistrationStatus();
}
Serial.println(F("Network registration OK"));
delay(1000);
bool success = sim800l->setupGPRS(APN);
while (!success) {
success = sim800l->setupGPRS(APN);
delay(5000);
}
Serial.println(F("GPRS config OK"));
}
uint16_t readVL53L0X() {
uint16_t distance = 0;
Wire.beginTransmission(VL53L0X_ADDRESS);
Wire.write(0x00); // Command register address
Wire.write(0x01); // Command to start measurement (Single Ranging Mode)
Wire.endTransmission();
// Wait for measurement to complete
delay(100); // Wait for data to become available
Wire.requestFrom(VL53L0X_ADDRESS, 2); // Request 2 bytes of data
if (Wire.available() >= 2) {
byte lowByte = Wire.read();
byte highByte = Wire.read();
distance = (highByte << 8) | lowByte; // Convert to 16-bit value
}
return distance;
}
Output:
Module is ready
Signal OK (strength: 19)
Network registration OK
GPRS config OK
GPRS connected with IP 100.96.164.15
18
Start HTTP GET…
Temperature: 28
Distance: 59392
HTTP GET error 702
GPRS disconnected!
Module in low power mode
This code works and outputs a response
#include <SoftwareSerial.h>
#include "SIM800L.h"
#include <DHT.h>
#define SIM800_RX_PIN 8
#define SIM800_TX_PIN 9
#define SIM800_RST_PIN 4
DHT dht(3, DHT11);
const char APN[] = "internet";
const char URL[] = "########";
SIM800L* sim800l;
void setup() {
dht.begin();
Serial.begin(115200);
while (!Serial);
SoftwareSerial* serial = new SoftwareSerial(SIM800_RX_PIN, SIM800_TX_PIN);
serial->begin(9600);
delay(1000);
sim800l = new SIM800L((Stream *)serial, SIM800_RST_PIN, 200, 512);
setupModule();
}
void loop() {
// Perform the HTTP GET request process
performHttpGetRequest();
// Go into low power mode for 10 minutes
bool lowPowerMode = sim800l->setPowerMode(MINIMUM);
if (lowPowerMode) {
Serial.println(F("Module in low power mode"));
} else {
Serial.println(F("Failed to switch module to low power mode"));
}
// Delay for 10 minutes (600 seconds)
delay(600000);
// Wake up from low power mode
bool normalPowerMode = sim800l->setPowerMode(NORMAL);
if (normalPowerMode) {
Serial.println(F("Module in normal power mode"));
} else {
Serial.println(F("Failed to switch module to normal power mode"));
}
}
void performHttpGetRequest() {
// Establish GPRS connectivity (100 trials)
bool connected = false;
for (uint8_t i = 0; i < 100 && !connected; i++) {
delay(1000);
connected = sim800l->connectGPRS();
}
// Check if connected, if not reset the module and setup the config again
if (connected) {
Serial.print(F("GPRS connected with IP "));
Serial.println(sim800l->getIP());
Serial.println(sim800l->getSignal());
} else {
Serial.println(F("GPRS not connected!"));
Serial.println(F("Resetting the module."));
sim800l->reset();
setupModule();
return;
}
Serial.println(F("Start HTTP GET..."));
int t = dht.readTemperature();
String fullUrl = String(URL) + String(t);
Serial.println(t);
// HTTP GET communication with 10s for the timeout (read)
uint16_t rc = sim800l->doGet(fullUrl.c_str(), 18000);
if (rc == 200) {
// Success, output the data received on the serial
Serial.print(F("HTTP GET successful ("));
Serial.print(sim800l->getDataSizeReceived());
Serial.println(F(" bytes)"));
Serial.print(F("Received: "));
Serial.println(sim800l->getDataReceived());
} else {
// Failed...
Serial.print(F("HTTP GET error "));
Serial.println(rc);
}
delay(1000);
// Close GPRS connectivity (5 trials)
bool disconnected = sim800l->disconnectGPRS();
for (uint8_t i = 0; i < 5 && !disconnected; i++) {
delay(1000);
disconnected = sim800l->disconnectGPRS();
}
if (disconnected) {
Serial.println(F("GPRS disconnected!"));
} else {
Serial.println(F("GPRS still connected!"));
}
}
void setupModule() {
// Wait until the module is ready to accept AT commands
while (!sim800l->isReady()) {
Serial.println(F("Problem initializing AT command, retrying in 5 sec"));
delay(5000);
}
Serial.println(F("Setup complete!"));
// Wait for the GSM signal
uint8_t signal = sim800l->getSignal();
while (signal <= 0) {
delay(1000);
signal = sim800l->getSignal();
}
Serial.print(F("Signal OK (strength: "));
Serial.print(signal);
Serial.println(F(")"));
delay(1000);
// Wait for operator network registration (national or roaming network)
NetworkRegistration network = sim800l->getRegistrationStatus();
while (network != REGISTERED_HOME && network != REGISTERED_ROAMING) {
delay(1000);
network = sim800l->getRegistrationStatus();
}
Serial.println(F("Network registration OK"));
delay(1000);
// Setup APN for GPRS configuration
bool success = sim800l->setupGPRS(APN);
while (!success) {
success = sim800l->setupGPRS(APN);
delay(5000);
}
Serial.println(F("GPRS config OK"));
}
Thensyst is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.