I've done a lot of searching but have yet to find any examples of the data format for accessing a simple BLE characteristic. I have a CC41 (HM-10 clone) that I have set to master mode and successfully connected to a BLE server device using a PC terminal program and the AT commands. I now want to send the proper data to access a service such as Immediate Alert (0x1802) and it's Alert Level characteristic (0x2A06). I know the full service and characteristic UUIDs and the data value for turning the alert on/off. I can do so from the nRF phone app but it doesn't tell me the data protocol that is actually sent from the app. I assume that the UUID needs to be sent as hex data, not a string, but nothing I've tried so far works. If the phone app can do it, then I would think that I can do it manually as well. Any ideas?
Related
I am attempting to use HM10 as central to read data from a sensor. The HM10 has been flashed with the latest firmware V710 to use the self learn functionality.
Here is the list of messages I am sending and receiving from the HM10
First I configure the HM10 as central and turn on some notifications. Then I connect to the MAC address of the sensor. I use the AT+FINDSERVICES? command to get the list of services, then find all the characteristics in the range of that uuid. The characteristics I am interested in is 0021.
But here is when the problems start. If I try to read that characteristic I get OK+DATA-ER, which the datasheet the characteristic does not have a read property. Same thing with notify.
But from the AT+CHAR command we can see handle 0021 has both read and notify. I have also tired reading from 001E handle and I get the same error. I am able to read data like the device name from another handle so I am able to get some data off the sensor.
I am wondering if the OK+DATA-ER response can mean something else? Or if the characteristic handle isn't correct somehow. If that were the case how would I find the correct handle?
I have tried connecting to the sensor on my iphone using the LightBlue app and I am able to both read and subscribe to the notification. I have also tried cloning the sensor as a virtual device on LightBlue and I am able to read and subscribe from the HM10 to the phone. So the issue seem to be between the HM10 and the sensor specifically and not with either device individually.
LightBlue UUID
LightBlue read data
I figured it out. Turned out to be a security issue. The sensor would allow connection but no data would be accessible unless the connection was encrypted.
The BLE sensor required pairing when it first connect to a phone and does not subsequently so I missed that fact when I was trying to connect to it via the HM-10.
I don't believe the HM-10 supports pairing connection. I tried setting AT+TYPE to other than 0 but it would no longer connect to the sensor. I would get OK+CO11A but it wouldn't finish connecting.
I switched to an ESP32 board and used
BLEDevice::setEncryptionLevel(ESP_BLE_SEC_ENCRYPT);
This allowed me to read and subscribe to the characteristic.
I'm developing web based game based on Wemos d1 Mini, and for users to enter their wifi address so that it connect to WiFi, I have to provide the arduino sketch.
To avoid cheating, is there way to disable section of code to be edited or lock some variables so that it cannot be changed in arduino IDE?
Thanks in advance.
No, but you can provide other means of entering configuration data.
ESP can emulate EPROM, or you can read from Serial/LittleFS/SPIFFS before you establish a WiFi connection.
If the user has access to your source code, there's no "cheating", that's improving your code. :)
There are many ways to not have your user edit the sketch to enter WIFI credentials.
To name the most obvious
have them entered via serial interface
have them provided via a file on a SD card for example
have them entered using some kind of user interface
use WPS
about the anti-cheat stuff I suggest you do some further research how things can be approached. this cannot be answered given the provided information
You start by creating an access point with set SSID/password users should receive from you and you also create a web server to accept user's credentials for their WiFi network. You can do that using a GET string or create a page with fields.
Once credentials entered by the user you store it in flash or EEPROM or whatever facilities exists, and you reboot the device.
When device starts it checks the credentials and tries to connect, if it fails you go back to the access point and web server stage.
I bought one of these:
https://www.aliexpress.com/item/Smart-finder-Key-finder-Wireless-Bluetooth-Tracker-Anti-lost-alarm-Smart-Tag-Child-Bag-Pet-GPS/32806261079.html
As far as I can tell it is a BLE (Bluetooth Low Energy) location tag.
I downloaded the app for it onto my iphone, and the app instantly recognised it and connected to it. The iPhone app seems to know how far away the tag is - it has a little map of the local area and says how many feet away. I was able to set the device name via the app, but I'm not sure if that set it locally or on the tag itself. The iPhone app also has a "find" button - when you press it, the tag beeps.
So I want to know how I can program this thing myself. I want to be able to identify it when it is nearby, connect to it and make it beep. I've searched for quite a while but not come up with much.
I'm assuming (wrongly/rightly?) that there is some general standard or approach for talking to these BLE location devices and carrying out the basic functions with them - but what is that standard - where is the documentation?
Does anyone have any idea how to program these BLE location tag devices?
BLE devices typically communicate using GATT, either using standard GATT services, or custom ones. The command to make it beep is probably implemented using a custom GATT service.
For finding out the distance to the beacon, typically the RSSI is used. This is a measure of the received power. It needs to be compared to the output power at the emitter. Usually beacons will put their output power in advertisement data, so it can be used without connecting to them. Here since the app is also able to send commands to the beacon, chances are it keeps a connection to it and has a custom GATT protocol to retrieve the output power.
Here is what I would suggest:
Read up on BLE, especially advertising and GATT. For instance read this for advertising and this for GATT. The full BLE spec is available here but should be used for reference and not introduction
Sniff the communication between your device and your phone. You can see this other answer of mine to get started
Replicate the communication protocol in you own app. For that you'll need to use your target platform's BLE libraries. For instance for iOS it is CoreBluetooth
I want to try to set up an ESP8266 (using the Arduino IDE) to occasionally connect to a wifi SSID to send telemetry back. I also would really like to be able to have it running a softAP for configuration/settings purposes. (i.e. so if you want to change internal settings in your code, you can connect directly to the device to access a web form to do so)
The problem is, I am not 100% sure how I know which is which when making an outgoing telemetry json query. I want it to go out on the STATION mode connection. Presumably in most cases the AP mode won't be connected, but there may be rare instances where both are connected at the same time. Thus how do I tell the device to specifically use the STA side of things when it needs to send data back over the internet?
I can't even seem to find any specific examples to ask if one or the other is connected. (you can poll WiFi.status() but - which one is it reporting?)
Any help is appreciated
I have an Arduino Uno that is successfully registered as a device with IBM IoTF. It can send information to the Bluemix Node-RED app without any issues now.
Now, I would like the Node-RED app to send commands to the device (the Arduino Uno). The Arduino is subscribed to the MQTT without any error. But, it is not receiving any commands from the Node-RED. I followed the directions at the link below to create another flow in Node-RED to show when a command is published and the commands are being shown, so they seem to be going to the MQTT broker. But, the device (Arduino) is not receiving them.
How can I figure out how to get this working?
Node-RED, IOT Foundation Out Node Not Sending Commands
I have the IBM IoT Out Node parameters set as follows:
Authentication: Bluemix Service
Output type: Device command
Device type: Arduino-tempsensor (this is the same string I used for the device type (name) when I registered it in IoTF)
Device ID: I put the MAC address here, should it be more
Command Type: status (I used the word "status" here. Does capitalization matter? Where should I get this value from? I used "status" because it is in the topic: "iot-2/cmd/status/fmt/json" is that correct?)
Format: json (does capitalization matter here?)
data: {"d":{"myName":"Arduino Uno", "temperature":989}} (I used this because it's JSON and I wanted to just see anything at the device)
Name: IBM IoT App Out
I typed up this whole question and then it occurred to me that the test flow to look for the published command should have all of the parameters set to exactly the same as the output. When I tried that, I was not getting the command message coming back. Then, I realized that my mac address (device ID) was capitalized in one place, but not the other. The MAC address (Device ID) I used to register the device was all in caps, so I make the Iot-out node for the command so that it was all capitalized and made the Iot-in node to test for the message so that it was all capitalized. Now it works! Then, I looked back at the device (which was printing to the serial monitor so I could see what was happening) and I am now seeing the messages! So, make sure your parameters follow the same capitaliztion!