Skip to content

Unable to connect Nano 33 IoT to Arduino Science Journal App #3

Open
@ax-sc

Description

@ax-sc

The official reference (https://www.arduino.cc/reference/en/libraries/arduino_sciencejournal/) states that this library is compatible with the Arduino Nano 33 IoT - Board. As there is no example code provided, I tried to derivate it from the given firmware for the Arduino Nano 33 BLE Sense and came up with this "minimal" code, which I was able to compile and upload to a Nano IoT.

#include <ArduinoBLE.h>

const int VERSION = 0x00000001;

#define UUID(val) ("cfccb0fd-" val "-4da3-afaf-a4305a6b64b3")

#define DEBUG 1

BLEService service (UUID("0000"));
BLEUnsignedIntCharacteristic versionCharacteristic (UUID("0001"), BLERead);
BLEFloatCharacteristic testCharacteristic (UUID("0002"), BLENotify);

String name;
unsigned long lastNotify = 0;

void printSerialMsg(const char * msg) {
  #ifdef DEBUG
  if (Serial) {
    Serial.println(msg);
  }
  #endif
}

void updateSubscribedCharacteristics() {
    if (testCharacteristic.subscribed()) {
    float test = 3.141;
    testCharacteristic.writeValue(test);
  }
}

void setup() {
  #ifdef DEBUG
  Serial.begin(9600);
  while (!Serial);
  Serial.println("Started");
  #endif

  delay(5000);

  if (!BLE.begin()) {
    printSerialMsg("Failed to initialized BLE!");
  }

  String address = BLE.address();
  #ifdef DEBUG
  if (Serial) {
    Serial.print("address = ");
    Serial.println(address);
  }
  #endif
  address.toUpperCase();

  name = "Nano IoT - ";
  name += address[address.length() - 5];
  name += address[address.length() - 4];
  name += address[address.length() - 2];
  name += address[address.length() - 1];

  #ifdef DEBUG
  if (Serial) {
    Serial.print("name = ");
    Serial.println(name);
  }
  #endif

  BLE.setLocalName(name.c_str());
  BLE.setDeviceName(name.c_str());
  BLE.setAdvertisedService(service);

  service.addCharacteristic(versionCharacteristic);
  service.addCharacteristic(testCharacteristic);

  versionCharacteristic.setValue(VERSION);

  BLE.addService(service);
  BLE.advertise();

  digitalWrite(LED_BUILTIN, HIGH);
}

void loop() {
  while (BLE.connected()) {
    unsigned long now = millis();
    if (abs((long) now - (long) lastNotify) >= 100) {
      updateSubscribedCharacteristics();
      lastNotify = now;
    }
  }
}

After compiling and uploading this, I was able to see the advertised services in a BLE scanner (used LightBlue) and could see the Nano IoT as a connected device in my settings.

IMG_2136
IMG_2137

As a consequence, i would have expected the Nano IoT and the testCharacteristic to be listed as sensor in the App, but neither the device nor the characteristic is shown. I have been using the latest version of this library and of the ArduinoBLE library as well. The device used is an iPhone 5s and the latest version of the Arduino Science Journal App is installed.

I was not able to find any documentation on how a service has to be structured such that the App accepts it as a sensor. As you are providing this library for connecting Arduino devices to the App, i´m placing this issue here but if you think it would be more appropiate in the App-repository, feel free to transfer it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: imperfectionPerceived defect in any part of project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions