Data Gator
Hardware and software documentation for the Data Gator project.
Loading...
Searching...
No Matches
MinewS1.hpp
Go to the documentation of this file.
1
8#ifndef MINEW_S1_H
9#define MINEW_S1_H
10
11#include <Arduino.h>
12#include <sstream>
13#include <string.h>
14
15#include <../../include/BLESensor.hpp>
16#include <NimBLEAdvertisedDevice.h>
17#include <MQTTMailer.hpp>
18
19#define ENDIAN_CHANGE_U16(x) ((((x)&0xFF00)>>8) + (((x)&0xFF)<<8))
20#define ENDIAN_CHANGE_U32(x) ((((x)&0xFF000000)>>24) + (((x)&0x00FF0000)>>8)) + ((((x)&0xFF00)<<8) + (((x)&0xFF)<<24))
21
22extern const bool USB_DEBUG;
23
27class MinewS1: public BLESensor{
28public:
29 MinewS1(){}
30
31 static MinewS1& getInstance(){
32 static MinewS1 instance;
33 return instance;
34 }
35
36 bool advertisedDeviceIsS1(NimBLEAdvertisedDevice* dev); // true if the data in this payload is from S1
37 MQTTMail* parseAdvertisedData(NimBLEAdvertisedDevice* dev); // get the data from a scanned device
38
42 float getTemp();
43
47 float getHumidity();
48
52 int getVoltage();
53
58
63
67 std::string toJSON(double temp, double humidity); // export all known information to json string object
68 //
72 std::string getSensorType();
73
74
75private:
76 int serviceCount = 3; // how many services are stored in the list below, needed for iterating over the list in checks
77 NimBLEUUID s1_services[3] = {NimBLEUUID("0000ffe1-0000-1000-8000-00805f9b34fb"), // HT
78 NimBLEUUID("0000fff1-0000-1000-8000-00805f9b34fb"), // Eddystone URL
79 NimBLEUUID("0000feaa-0000-1000-8000-00805f9b34fb")}; // Eddystone TLM
80
84 struct { // HT data
85 uint8_t id = 0x00; // payload id
86 uint16_t unknown = 0x0000; // 2 bytes of useless data
87 int16_t temp = 0x0000; // temperature in Celsius as a float
88 uint16_t humidity = 0x0000; // relative humidity as a float
89 uint8_t address[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // S1 MAC address
90
91 // convert to a string of information
92 std::string toString(){
93
94 std::stringstream ss;
95 ss << ((float)ENDIAN_CHANGE_U16(temp))/256 << " C, "
96 << ((float)ENDIAN_CHANGE_U16(humidity))/256 << "%RH";
97
98 return ss.str();
99
100 }
101
103
107 struct { // INFO data
108 uint8_t id = 0x00; // payload id
109 uint16_t unknown = 0x0000; // 2 bytes of useless data
110 uint8_t address[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // S1 MAC address
111 char name[2] = {0x00, 0x00};
112
113 // convert to a string of information
114 std::string toString(){
115
116 auto size = 18;
117 char *res = (char*)malloc(size);
118 snprintf(res, size, "%02x:%02x:%02x:%02x:%02x:%02x", address[5], address[4], address[3], address[2], address[1], address[0]);
119 std::string ret(res);
120 free(res);
121 std::stringstream ss;
122 ss << "MAC: " << ret << ", "
123 << "Name: "<< name[0] << name[1];
124
125 return ss.str();
126 }
127
129
133 struct { // Eddystone Telemetry data
134 uint8_t frameType = 0x00; // eddystone frame specifier
135 uint8_t version = 0x00; // version...
136 uint16_t volt = 0x0000; // voltage of sensor battery in mV
137 int16_t temp = 0x0000; // temperature reading as float in Celsius
138 uint32_t advCount = 0x00000000; // how many advertisements have been broadcast
139 uint32_t tmil = 0x00000000; // time up, days, hours, minutes, you get the idea
140
141 std::string toString(){
142
143 std::stringstream ss;
144 ss << "V" << (int)version << ".0, "
145 << ENDIAN_CHANGE_U16(volt) << "mV, "
146 << ((float)ENDIAN_CHANGE_U16(temp))/256 << " C, "
147 << advCount << ", "
148 << ENDIAN_CHANGE_U32(tmil) << " seconds";
149
150 return ss.str();
151
152 }
153
155
159 struct { // iBeacon UUID, Major, & Minor data
160 uint8_t manufacturerID[6];
161
162 std::string toString(){
163 return "";
164 }
165
167
168};
169
170#endif
std::string toString()
Convert struct members upper and lower to a string double value.
Definition KKM_K6P.hpp:8
#define ENDIAN_CHANGE_U16(x)
< Converts endianess for 16 bit integers
Definition KKM_K6P.hpp:20
const bool USB_DEBUG
USB serial debugging enabled.
Definition main.cpp:62
Defines a bluetooth low energy (BLE) interface for integrating new sensors into the DG firmware.
Definition BLESensor.hpp:20
An object that stores data from which a topic and message can be extracted for publishing to an MQTT ...
Definition MQTTMailer.hpp:37
Singleton used to identify and parse BLE transmissions from MinewS1 BLE Temperature and Humidity sens...
Definition MinewS1.hpp:27
float getTemp()
Read the temperature from the sensor data packet.
Definition MinewS1.cpp:131
std::string getSensorType()
Get the string identifier for the sensor brand and model.
Definition MinewS1.cpp:171
BLEAddress getMAC()
Read the sensor BLE MAC address from the sensor data packet.
Definition MinewS1.cpp:161
MQTTMail * parseAdvertisedData(NimBLEAdvertisedDevice *dev)
Retrieve data advertised by the device and save it if of interest.
Definition MinewS1.cpp:33
int getVoltage()
Read the sensor's battery voltage from the sensor data packet.
Definition MinewS1.cpp:152
float getHumidity()
Read the humidity from the sensor data packet.
Definition MinewS1.cpp:143
std::string toJSON(double temp, double humidity)
Convert temperature and humidity values to a JSON object string.
Definition MinewS1.cpp:175
struct MinewS1::@4 __attribute__((packed)) HT_Frame
HT data struct.
bool advertisedDeviceIsS1(NimBLEAdvertisedDevice *dev)
Check if the advertised device is a Minew S1 sensor.
Definition MinewS1.cpp:11
uint32_t timeUp()
Read the time the sensor has been running from the sensor data packet.
Definition MinewS1.cpp:156
int reset_count
number of resets retrieved for NVS
Definition scheduler.hpp:31