Data Gator
Hardware and software documentation for the Data Gator project.
Loading...
Searching...
No Matches
ble_util.hpp
Go to the documentation of this file.
1
20#ifndef BLE_UTIL_HPP
21#define BLE_UTIL_HPP
22
23#include <NimBLEAdvertisedDevice.h>
24#include <BLESensor.hpp>
25#include <MinewS1.hpp>
26#include <KKM_K6P.hpp>
27#include <logger.hpp>
28
35class ScanCallbacks: public NimBLEAdvertisedDeviceCallbacks {
36
45 void onResult(NimBLEAdvertisedDevice* dev){
46 //Serial.printf("Advertised Device: %s\n", dev.toString().c_str());
47 MinewS1 s1_interpreter = MinewS1::getInstance();
48 bool isS1 = s1_interpreter.advertisedDeviceIsS1(dev);
49
50 KKMK6P k6p = KKMK6P::getInstance();
51 bool isK6P = k6p.advertisedDeviceIsK6P(dev);
52
53 if(isK6P){
54 // parse data
55 MQTTMail* mail_ptr = k6p.parseAdvertisedData(dev);
56 if(USB_DEBUG) Serial.println("\t-> sent BLE mail to publisher");
57
58 MQTTMailer instance = MQTTMailer::getInstance();
59
60 if(WiFi.status() == WL_CONNECTED && !mqtt_client.connected()){
61 if(USB_DEBUG) Serial.println("\t-> not connected");
62 instance.reconnect(mqtt_client);
63 }
64
65 std::string msg = "{" + mail_ptr->getMessage() + ", \"GATOR_MAC\": \"" + WiFi.macAddress().c_str() + "\"}";
66 //instance.mailMessage(&mqtt_client, mail_ptr->getTopic(), msg);
67 log_data(mail_ptr->getTopic(), msg);
68 delete(mail_ptr);
69 mail_ptr = NULL;
70
71
72
73 }
74
75 if(isS1){
76 MQTTMail* mail_ptr = s1_interpreter.parseAdvertisedData(dev); // print the advertised data after interpretation
77 if(mail_ptr != NULL){
78 if(USB_DEBUG) Serial.println("\t-> sent BLE mail to publisher");
79 MQTTMailer instance = MQTTMailer::getInstance();
80
81 if(WiFi.status() == WL_CONNECTED && !mqtt_client.connected()){
82 if(USB_DEBUG) Serial.println("\t-> not connected");
83 instance.reconnect(mqtt_client);
84 }
85
86 std::string msg = "{" + mail_ptr->getMessage() + ", \"GATOR_MAC\": \"" + WiFi.macAddress().c_str() + "\"}";
87 //instance.mailMessage(&mqtt_client, mail_ptr->getTopic(), msg);
88 log_data(mail_ptr->getTopic(), msg);
89 delete(mail_ptr);
90 mail_ptr = NULL;
91 }
92 }
93 }
94};
95
96#endif
This file implements BLE Sensor generic interface.
Contains the definition of the KKM K6P BLE sensor, which is based on the BLESensor....
Implementation of the Minew S1 bluetooth sensor family. Extends BLESensor.hpp.
Singleton used to identify and parse BLE transmissions from KKMK6P BLE Temperature and Humidity senso...
Definition KKM_K6P.hpp:65
bool advertisedDeviceIsK6P(NimBLEAdvertisedDevice *)
Check if the advertised device is a KKMK6P sensor.
Definition KKM_K6P.cpp:11
MQTTMail * parseAdvertisedData(NimBLEAdvertisedDevice *dev)
Retrieve data advertised by the device and save it if of interest.
Definition KKM_K6P.cpp:35
An object that stores data from which a topic and message can be extracted for publishing to an MQTT ...
Definition MQTTMailer.hpp:37
std::string getTopic()
The topic/destination this MQTT object should be published to.
Definition MQTTMailer.cpp:20
std::string getMessage()
Convert the data fields to an MQTT message string which can be published.
Definition MQTTMailer.cpp:11
Converts MQTTMail objects into viable MQTT messages so that they can be published.
Definition MQTTMailer.hpp:60
void reconnect(PubSubClient mqtt_client)
Attempt to reconnect to MQTT broker every 5 seconds until successful.
Definition MQTTMailer.cpp:48
Singleton used to identify and parse BLE transmissions from MinewS1 BLE Temperature and Humidity sens...
Definition MinewS1.hpp:27
MQTTMail * parseAdvertisedData(NimBLEAdvertisedDevice *dev)
Retrieve data advertised by the device and save it if of interest.
Definition MinewS1.cpp:33
bool advertisedDeviceIsS1(NimBLEAdvertisedDevice *dev)
Check if the advertised device is a Minew S1 sensor.
Definition MinewS1.cpp:11
Callbacks for BLE packets.
Definition ble_util.hpp:35
void onResult(NimBLEAdvertisedDevice *dev)
What to do when a device has been picked up by the scan.
Definition ble_util.hpp:45
Logging Utilities for detecting and selecting logging interfaces.
void log_data(std::string topic, std::string message)
Definition logger.hpp:32
const bool USB_DEBUG
USB serial debugging enabled.
Definition main.cpp:62
PubSubClient mqtt_client
MQTT client object for logging.