-
-
Notifications
You must be signed in to change notification settings - Fork 179
NimBLE_Client + Beacon BLE #215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @lucasromeiro I am unable to see the picture in the link. I can say that if you have saved the pointer to the advertised device or the address of it you should be able to connect to it. Maybe you could provide a log output and/or code example? |
Ok, the easiest thing to change is this line to the service UUID of your device (FFF0). So change that to That should get you connected to it, after that you will need to get the services and characteristics from it and read/write to them. I don't know what the UUID's are except for the one you mentioned but you can use We can go over that process once you get connected to the device, let me know. |
NICE!!! THANKS!!!! Can you explain better how to do the loop to discover the services and features? After I discover these services, how do I use them? One last important question, I have another BLE device, but it does not return this code 000F that worked on this one, how do I do it in these cases? Would I put the name? the MAC? Do you have these options? Thank you very much for all your help, it will solve a problem of mine !!! Other beacon scan: Found another manufacturers beacon! |
You will have quite a bit of work to do here but I will try to explain the work flow as best I can.
To connect to the other device I suggest comparing the name instead of the UUID since it does not advertise it. |
Hello, I managed to adapt to make it work! The code I modified some things that had silly errors and put in this place. is correct? I did not find the codes for temperature and humidity. =( Here is a table of all the codes, none of them are for temperature and humidity. as for your suggestion to put the name of the sensor, I think it will be better to put MAC, so I will be able to differentiate both, Would it be possible to work like this? if(advertisedDevice->isAdvertisingService(NimBLEUUID("MAC HERE!!!!"))) |
Glad you got that sorted. You will need to change the service/characteristic |
Sorry, I didn't look well enough at the service UUID's. The service you want is |
Hi! I did the tests, look at the prints below. I get paid but I still can't see the temperature and humidity. What can I do? For 180a (2a2a): For 180a (2a50): what is this(tasty)? |
lol that's just silly code that is for demonstration, you should remove all of that as you don't need it. I don't know what the values are that you are getting, the device doesn't seem to be using the standard temp/humidity characteristics. Maybe search google for information on that device, probably someone has figured it out already. One thing you can try also is changing the temperature read to this: |
Got it, how do you suggest that I search? Wouldn't this data that I received and show above be correct and out of order? Perhaps it is correct and just needs to be interpreted correctly. What do you think? TEST: int16_t temperature = pChar->readValue<int16_t>(): For 180a (2a50): For 180a (2a2a): These codes according to the table say something else. Are we not looking at the wrong data? |
Yes those do look to be the wrong data, however I do not see the standard temp / humidity characteristics available so I guessed that they used those instead for some reason. The temperature should be UUID |
Thanks, I think I see what it's doing now, it will only send the data over notifications. To do that you will have to subscribe to UUID So you can remove all the readvalue code and just change it to get those UUID's and call |
Hello, what would notifications be, what is the difference for the method we were doing? I like to understand how it works. That's why I ask questions. (Thank you for your help) I didn't quite understand what I should do now to make these notifications work. Can I simulate this by the application I downloaded on my cell phone and validate that it will work? If we can validate the reading using the application I think it is easier to qchar the correro command. not? but I don't know how to translate these results. to find out if it is correct. App result: A2A2: 2A50: How I can see it? |
Yes this is a different operation, there is no reading or writing of characteristics that need to be done for this device. You can also do this on your phone when you click on the enable notifications button in the screen pic you posted earlier. When you do this you should see the characteristic value being updated once in a while. The basic concept is connect->subscribe to the characteristic notifications->wait for data, nothing more to do. I think you would benefit more from a little more study of BLE concepts so you'll understand more of what you're doing. |
I think this is a difficult device to work with as it is using non-standard characteristics. Anyway, with notifications enabled as you show above, you should see the value being updated every so often, if not, try writing a value You're doing fine, keep up the work, this is just a particularly difficult device to work with. |
It seems very difficult to even work with these devices. Your tips are helping me a lot! I don't know anyone else who can help me with this. As it is a device that does not follow a standard, it will be difficult to solve it yourself. (thanks for all the help!) I tried to do what you told me to do, but by signing the notification by clicking on the 3 down arrows that are circled, no photo, I didn't get anything. no variables have been updated. nothing kept updating itself. :( I tried to do what you asked and I wrote 1. I tried to write bit, utf8, etc. I tried to write other values, I also wrote in the other data sending fields. The only time something changed was when I sent bit 1 on FFF5. this appears the value that is circled in red in the photo. that value has not changed anymore. |
That looks like you've got it solved, writing |
Hello, is that what I should do in the code? I'm not quite sure what to do now. Modify notifyCB? how? Regarding the change in fff5 that caused a notification in fff3, it doesn't seem like anything I'm expecting. It cannot be temperature or humidity in any shape. I investigated and found no relationship. There must be some other code to be sent and get the correct variables (I imagine). |
In that code you have subscribed to |
Now is correct? ` /** Now we can read/write/subscribe the charateristics of the services we are interested in /
` The device is "WS02": https://www.aliexpress.com/item/1005001626596814.html?spm=a2g0s.9042311.0.0.27424c4d3lFjTo |
That's not quite correct, try:
Try that, let me know what happens. |
I tried looking up some info on this and couldn't find much. Perhaps @1technophile has seen this type of thing before? |
The code: `
` Result: |
Maybe a different approach could be to check if the device advertises temperature and humidity, this way you would avoid the BLE connection and save its battery life. So as to check this, you scan the device several times, take notes of the manufacturer data and service data read, record the temperature from the app and see if there is a correlation. If you want to go this track, post here, the scan results and what you see in the app after the scan. I think 5-10 scans data are necessary. |
This world is too small! I was looking at @1technophile work because I have a LYWSD03MMC sensor here with me! I'm looking to talk to @1technophile see if he can help me with this. I saw his GITHUB code. It is very extensive and professional. Some things I don't understand. I was VERY happy that you guys know each other! |
Here is what we need for at least 5 scans, would be better with big amplitudes of temp and hum, so as to get relevant measurement value, I suggest that you find the app corresponding to the beacon and check the temp and hum on it.
|
I believe this is what you asked for:
|
It is strange that your temp doesn't change. Could you try to add lines with different temperatures by changing the sensor location. |
A track to follow for the humidity (got help from this): 10 00 00 00 1a 11 00 00 f7 70 58 0c f5 01 5a 04 6e 09 00 00 31.31 69.6 |
For the temp: 10 00 00 00 1a 11 00 00 f7 70 58 0c f5 01 5a 04 6e 09 00 00 31.31 69.6 For the battery |
Much simpler than I imagined. Can we get some more useful information out of that string? |
If you don't mind I'm going to add it to OpenMQTTGateway :-) JsonObject& process_ws02(JsonObject& BLEdata) {
const char* manufacturerdata = BLEdata["manufacturerdata "].as<const char*>();
double temperature = (double)value_from_hex_data(manufacturerdata , 20, 4, true) / 16;
double humidity = (double)value_from_hex_data(manufacturerdata , 24, 4, true) / 16;
double voltage = (double)value_from_hex_data(manufacturerdata , 16, 4, true) / 1000;
//Set Json values
BLEdata.set("tempc", (double)temperature);
BLEdata.set("tempf", (double)convertTemp_CtoF(temperature));
BLEdata.set("hum", (double)humidity);
BLEdata.set("volt", (double)voltage);
return BLEdata;
}
/**
* Retrieve an unsigned long value from a char array extract representing hexadecimal data, reversed or not,
* This value can represent a negative value if canBeNegative is set to true
*/
long value_from_hex_data(const char* service_data, int offset, int data_length, bool reverse, bool canBeNegative = true) {
char data[data_length + 1];
memcpy(data, &service_data[offset], data_length);
data[data_length] = '\0';
long value;
if (reverse) {
// reverse data order
char rev_data[data_length + 1];
revert_hex_data(data, rev_data, data_length + 1);
value = strtol(rev_data, NULL, 16);
} else {
value = strtol(data, NULL, 16);
}
if (value > 65000 && data_length <= 4 && canBeNegative)
value = value - 65535;
Log.trace(F("value %D" CR), value);
return value;
} |
I don't care, you can use it however you want. You are the one who discovered it. (brilliant idea) |
Could be nice! Can you share the links where you bought them, please? |
I think the issue can be closed, you can open a thread into OpenMQTTGateway forum so as to discuss the others. |
Yes, sure! https://www.aliexpress.com/item/1005001626596814.html?spm=a2g0s.9042311.0.0.27424c4d3lFjTo |
Ha, nice work here, thanks @1technophile. More things to add to your gateway 😄 |
Yes! Thanks guys!! |
Your code is well advanced for me. Can you help me simplify so that I understand? My code:
|
long value_from_hex_data(const char* service_data, int offset, int data_length, bool reverse, bool canBeNegative = true) {
char data[data_length + 1];
memcpy(data, &service_data[offset], data_length);
data[data_length] = '\0';
long value;
if (reverse) {
// reverse data order
char rev_data[data_length + 1];
revert_hex_data(data, rev_data, data_length + 1);
value = strtol(rev_data, NULL, 16);
} else {
value = strtol(data, NULL, 16);
}
if (value > 65000 && data_length <= 4 && canBeNegative)
value = value - 65535;
//Log.trace(F("value %D" CR), value);
return value;
}
void revert_hex_data(const char* in, char* out, int l) {
//reverting array 2 by 2 to get the data in good order
int i = l - 2, j = 0;
while (i != -2) {
if (i % 2 == 0)
out[j] = in[i + 1];
else
out[j] = in[i - 1];
j++;
i--;
}
out[l - 1] = '\0';
}
void process_ws02( char* manufacturerdata) {
Serial.print("Temperature:");
Serial.println(value_from_hex_data(manufacturerdata , 20, 4, true) / 16);
Serial.print("Humidity:");
Serial.println(value_from_hex_data(manufacturerdata , 24, 4, true) / 16);
Serial.print("Voltage:");
Serial.println(value_from_hex_data(manufacturerdata , 16, 4, true) / 1000);
} Begin with BLE scan example And add the function call After having extracted the manufacturer data with: |
@1technophile Nice! Thanks!!! How do you suggest that I post about the other models on your forum? |
@lucasromeiro could you test this branch and see if it works please:
Ideally if you could post one topic for each sensor with the scanned data it would be great. |
hi everyone I bought this thermobeacon. I understood that the thermobeacon sends the temperature and humidity data to the sensor blue app on the smartphone via adv_packet. He wants to know if anyone knows how to change these temperature and humidity values. Let me explain ... my goal is to have the wrong humidity and temperature data displayed on the phone app (eg temperature 20 ° I would like to inject a temperature of 40 °. Please someone help me! Thanks. link thermobeacon: https://www.amazon.de/ORIA-Kabelloses-Thermometer-Thermo-Hygrometer-Export-funktion-2-x-bluetooth/dp/B08DL5NN58 |
LOL, playing tricks on people? As much fun as that would be it isn't really possible to do unless you can access and reflash the device or create your own imitation device that the phone will detect as legitimate. |
@h2zero Hi, thanks for answering me. I sniffed the packets between thermobeacon and smartphone (with ubertooth) and captured the connection. How can I make the imitation device that the phone will detect how to transfer? |
Just create a server with the same services/characteristics/descriptors as the original and copy the advertisement format/data. This may take a bit of time on your part but if you can sniff the data and it's not encrypted you should be able to do it. |
@h2zero can I clone it with nRF Connect for example? |
You can clone the device services etc.. with nRFConnect but not the advertisements I don't think. |
Hello, first I would like to congratulate you for the excellent work!
I have a small challenge:
I always used esp8266.
Now I need to connect an esp32 to a temperature and humidity (BLE) sensor.
I'm going to send a picture of him here.
I used your Scan example and it worked, found the equipment!
But, I am not able to connect to the BLE beacon to receive the temperature and humidity.
I tried to use the example NimBLE_Client.ino but was unsuccessful.
Would you help me? I didn't find many instructions and I really liked the example because it is very organized, I would like to make it work.
As there are no instructions in the example, I did not change anything.
I don't know what to do to change and read the Beacon variables (temperature and humidity)
Thank you so much for helping us all!
https://sc04.alicdn.com/kf/H4188ed456d95460a96dcffc01e015e6fl.jpg
Advertised Device found: Name: ThermoBeacon, Address: 70:f7:00:00:11:1a, manufacturer data: 100000001a110000f770830cef01be04c4300000, serviceUUID: 0xfff0, txPower: 0
The text was updated successfully, but these errors were encountered: