Skip to content
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

Example sketches for Lightblue Bean? #6

Closed
CloudMass opened this issue Dec 18, 2016 · 4 comments
Closed

Example sketches for Lightblue Bean? #6

CloudMass opened this issue Dec 18, 2016 · 4 comments
Labels

Comments

@CloudMass
Copy link

CloudMass commented Dec 18, 2016

Hi There,

I am trying to run it on Lightblue Bean but I get the error ble_protocol.h: No such file or directory after I have imported the CurieBLE and CurieIMU libraries.

In file included from /Users/xx/Documents/Arduino/libraries/CurieBLE/src/BLECharacteristic.h:23:0,
                 from /Users/xx/Documents/Arduino/libraries/CurieBLE/src/CurieBLE.h:20,
                 from /var/folders/0z/1bn_g74n64l51gh8czxrbyt80000gn/T/untitled1440007012.tmp/sketch_dec18b/sketch_dec18b.ino:2:
/Users/xx/Documents/Arduino/libraries/CurieBLE/src/BLECommon.h:25:54: fatal error: ../src/services/ble_service/ble_protocol.h: No such file or directory
 #include "../src/services/ble_service/ble_protocol.h"

You have any idea what could be wrong?

Thanks in advance.

@vojtamolda
Copy link
Owner

Hello @TechFactory,

Thanks for posting the question and using the plugin. The problem here is that most of the examples provide sketches only for Arduino 101, which is a different board than you have. Some examples like the humidity/ and thermometer/ also contain a sketch for Bluefruit Micro. There's no special reason to use only these BLE boards. Any board when programmed correctly will work with this plugin. I just happened to have these two at home, so I used them.

Unfortunately, the sketches are generally not compatible between different boards and require changes. That's why you see the puzzling error messages about missing ble_protocol.h file. The file really doesn't exist for your Bean, but it's needed to run on an Arduino 101.

Your Bean has a different set of functions that talk to the BLE subsystem. The best way to get started is these examples. Try to create a scratch characteristic, that turns on a LED, when you write 1 to it and turns the LED off when you write 0. When you match the UUIDs with the config.json from the lightbulb/ example, you should be able to get it working.

Sometimes it's a struggle, but when it's finally working HomeKit is a lot of fun and it's certainly worth it. I'll be happy to add support for more boards and merge a pull request with your new Bean example if you want to do it.

@vojtamolda vojtamolda changed the title ble_protocol.h: No such file or directory on Lightblue Bean Example sketches for Lightblue Bean? Dec 18, 2016
@CloudMass
Copy link
Author

CloudMass commented Dec 18, 2016

Hi @vojtamolda,

Thanks for the help.

I've made this so far. It's shows up in the home app on the iPhone but the temperature says 0 no matter what I do. Any idea?

#include <SPI.h>
#include <BLEPeripheral.h>

BLEPeripheral ble;
BLEService informationService("180A");
BLECharacteristic modelCharacteristic("2A24", BLERead, "101");
BLECharacteristic manufacturerCharacteristic("2A29", BLERead, "Arduino");
BLECharacteristic serialNumberCharacteristic("2A25", BLERead, "2.71828");

BLEService thermometerService("1D8A68E0-E68E-4FED-943E-369099F5B499");
BLEFloatCharacteristic temperatureCharacteristic("1D8A68E1-E68E-4FED-943E-369099F5B499", BLERead | BLENotify);

void setup() {
  
  Serial.begin(115200);

  ble.setLocalName("Thermo");
  ble.setAdvertisedServiceUuid(thermometerService.uuid());
  ble.addAttribute(informationService);
  ble.addAttribute(modelCharacteristic);
  ble.addAttribute(manufacturerCharacteristic);
  ble.addAttribute(serialNumberCharacteristic);

  ble.addAttribute(thermometerService);
  ble.addAttribute(temperatureCharacteristic);
  temperatureCharacteristic.setValue(0);

  ble.begin();
  
  Serial.println("Bluetooth on");
  
}

void loop() {
  
  ble.poll();

  int tempRead = Bean.getTemperature();
  temperatureCharacteristic.setValue(tempRead);
  Serial.print(tempRead);

  delay(3000);
  
}

Thanks again.

@vojtamolda
Copy link
Owner

I don't have a Bean to test, but I think you're puting an int value in place of a float value. HomeKit requires the temperatureCharacteristic to be of type BLEFloatCharacteristic . Try changing your code to something like this:

  float tempRead = (float) Bean.getTemperature();
  temperatureCharacteristic.setValue(tempRead);

The conversion is probably happening implicitly anyway, but getting the values to match is what matters here. You're seeing 0, because it's the default used by Homebridge when nothing is received.

Another way to check where is the problem is to use the LightBlue iOS app. When you change the type of the characteristic to float the number there has to match the output from the serial console.

@vojtamolda
Copy link
Owner

One more thing - Maybe I'm wrong, since I'm not very familiar with Bean's hardware, but I don't think it is currently supported by the BLEPeripheral library. Check the list of supported hardware here.

Bean is in fact an ATmega328p processor and the LBM313 module with battery. The module contains the CC2240 BLE SoC chip by Texas Instruments and an antenna in a nice FCC certified package.

Unfortunately the CC2240 isn't supported by the BLEPeripheral library as it was written for the competing Nordic Semiconductor's nRF5* family of chipsets. It's possible that the code will actually run, but it won't do anything useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants