Skip to content

Commit

Permalink
Fix serial init with SIM800L/BW16 (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephHewitt authored Oct 5, 2024
1 parent 44ce7f6 commit 296645c
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions B/B.ino
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,12 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
String ble_name = advertisedDevice.getName().c_str();
ble_name.replace(",","_");

await_serial();
serial_lock = true;
Serial.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str());
Serial1.print("BL,");
Serial1.print(advertisedDevice.getRSSI());
Serial1.print(",");
Serial1.print(advertisedDevice.getAddress().toString().c_str());
Serial1.print(",");
Serial1.println(ble_name);
serial_lock = false;
}
}
}
Expand Down Expand Up @@ -233,7 +229,7 @@ void setup() {
Serial.println("Using BW16 instead of SIM800L");
}

Serial2.begin(baud_rate); //SIM800L/BW16
Serial2.begin(baud_rate,SERIAL_8N1,16,17); //SIM800L/BW16
delay(50);
if (!using_bw16){
Serial.println("Requesting data from SIM");
Expand Down Expand Up @@ -272,8 +268,8 @@ void setup() {
pBLEScan = BLEDevice::getScan(); //create new scan
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
pBLEScan->setActiveScan(false); //active scan uses more power, but get results faster
pBLEScan->setInterval(50);
pBLEScan->setWindow(40); // less or equal setInterval value
pBLEScan->setInterval(100);
pBLEScan->setWindow(50); // less or equal setInterval value


Serial.println("Setting up multithreading");
Expand All @@ -282,7 +278,7 @@ void setup() {
"loop2", /* Name of the task */
10000, /* Stack size in words */
NULL, /* Task input parameter */
0, /* Priority of the task */
3, /* Priority of the task */
&loop2handle, /* Task handle. */
0); /* Core where the task should run */

Expand Down Expand Up @@ -396,16 +392,18 @@ void loop() {
}
}
}
BLEScanResults* foundDevices = pBLEScan->start(1.8, false);

await_serial();
serial_lock = true;
BLEScanResults* foundDevices = pBLEScan->start(1.8, false);
Serial1.print("BLC,");
Serial1.println(ble_found);
serial_lock = false;
Serial.print("Devices found: ");
Serial.println(ble_found);
Serial.println("Scan done!");
pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory
yield();
ble_found = 0;
if (last_temperature == 0 || millis() - last_temperature > 15000){
read_temperature();
Expand Down Expand Up @@ -467,6 +465,8 @@ void loop2( void * parameter) {
boolean had_gsm_data = false;
int count_5ghz = 0;
while (true) {
yield();
delay(10);
while (Serial1.available()){
//ESP A rarely talks to us, but it's usually important
String a_buff = Serial1.readStringUntil('\n');
Expand Down

0 comments on commit 296645c

Please sign in to comment.