При попытке отправить запрос на получение с помощью датчика VL53L0X выдается ошибка HTTP GET 702 (SIM800l), но без нее сC++

Программы на C++. Форум разработчиков
Ответить Пред. темаСлед. тема
Anonymous
 При попытке отправить запрос на получение с помощью датчика VL53L0X выдается ошибка HTTP GET 702 (SIM800l), но без нее с

Сообщение Anonymous »

У меня возникает ошибка при отправке данных с лазерного дальномера.
Я пробовал использовать библиотеку Adafruit_VL53L0X.h, но похоже, что она конфликтует с SIM800l .
Из-за этого подключил датчик без библиотеки но все равно вылазит ошибка 702. Если убрать лазерный дальномер все работает с dht11.
Как я могу решить эту проблему?
#include
#include
#include "SIM800L.h"
#include

#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 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 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 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"));
}



Подробнее здесь: https://stackoverflow.com/questions/787 ... 702-sim800
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C++»