Test
Revision 75:6606a580ebc4, committed 2019-01-23
- Comitter:
- HelGast95
- Date:
- Wed Jan 23 14:17:18 2019 +0000
- Parent:
- 74:12b9444a2fb4
- Child:
- 76:596c9924e51b
- Commit message:
- conversion a float del voltaje para enviarlo al JSON El BLE se desconecta cada vez que entra a la callback de read
Changed in this revision
| source/main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/source/main.cpp Wed Jan 23 10:54:17 2019 +0000
+++ b/source/main.cpp Wed Jan 23 14:17:18 2019 +0000
@@ -72,7 +72,6 @@
printf("Id: %s\r\n", BLEdata->id.c_str());
str = "Voltaje";
event["type"] = picojson::value(str);
- printf("Data: ");
event["data"] = picojson::value(BLEdata->voltaje);
BLEmpool.free(BLEdata);
@@ -88,6 +87,8 @@
printf("Se envia un evento por el puesto serie\r\n");
sendCharArrayToSerial(tmp, &pcSerial);
}
+
+ wait(1);
}
}
@@ -135,12 +136,11 @@
void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
{
/* Si se desconecta el dispositivo, volvemos a entrar en estado Advertising*/
- (void) params;
printf("Desconectado. Se comienza la fase de escaneo de nuevo\n\r");
serviceDiscovered = false;
BLE::Instance().gap().startScan(scanCallback);
}
-
+
void onDataReadClientCallback(const GattReadCallbackParams *response) {
if (response->handle == testServiceptr.getValueHandle()) {
printf("\r\n\r\nonDataReadClientCallback: handle %u, offset %u, len %u\r\n", response->handle, response->offset, response->len);
@@ -148,17 +148,25 @@
printf("[%02x]", response->data[index]);
}
printf("\r\n");
-
- // Enviamos datos al Mail para que los procese el thread del serial
+ printf("Que pasa\r\n");
+
BLEdata_t *BLEdata = BLEmpool.alloc();
+ printf("Eyyyyy\r\n");
int r = rand() % 500;
+ printf("Eyyyyy1.5\r\n");
char str[12];
+ printf("Eyyyyy1.6\r\n");
sprintf(str, "%d", r);
+ printf("Eyyyyy1.7\r\n");
BLEdata->id = str;
+ printf("Eyyyyy2\r\n");
uint16_t tensionaux;
tensionaux = ((response->data[1]) << 8) + (response->data[0]);
- BLEdata->voltaje = (tensionaux * 1.0 )/100;;
+ printf("Eyyyyy2.1\r\n");
+ BLEdata->voltaje = (tensionaux * 1.0 )/100;
+ printf("Eyyyyy2.2\r\n");
BLEqueue.put(BLEdata);
+ printf("Eyyyyy3\r\n");
}
}
@@ -206,9 +214,7 @@
ble.gattClient().onDataRead(onDataReadClientCallback);
ble.gap().setScanParams(500, 400);
- ble.gap().startScan(scanCallback);
-
- //printMacAddress();
+ ble.gap().startScan(scanCallback);
}
void scheduleBleEventsProcessing(BLE::OnEventsToProcessCallbackContext* context) {
@@ -224,7 +230,7 @@
}
void BLEServiceManagment() {
- eventQueue.call_every(1000, readVoltageValue);
+ eventQueue.call_every(2000, readVoltageValue);
BLE &ble = BLE::Instance();
ble.onEventsToProcess(scheduleBleEventsProcessing);
@@ -243,5 +249,8 @@
threadBLE.join();
threadSerial.join();
+ while(true) {
+ wait(100);
+ }
return 0;
}
\ No newline at end of file