Nano 33 IoT Receiving a BLE message then forwarding it to AWS over MQTT


I'm currently receiving 20 character blocks from BLE using the nano 33 IoT with the code below. The chars returned are then stored into a global array of strings called myStrings, and this portion prints correctly (There is probably a better way than a global stringArray here but returning the strings seemed to complicate things more).

String myStrings[20];
int i = 0;
while (peripheral.connected()) {
          if (myCharacteristic.valueUpdated()) {
            int l = 20;
            char values[l];
            myCharacteristic.readValue(values, 20);
            String temp = String(values);
            myStrings[i] = temp;

            Serial.println("myStrings[i] is");

I want to try and send this received message over MQTT using the following code

void publishMessage() {
  Serial.println("Publishing message");

I unfortunately cannot post more code than this due to potential IP issues, but I have verified that print is able to send string literals ie: "hello" over MQTT and those string literals are received on the AWS topic. There are catches for any potential errors in setting up BLE/MQTT and other functions, and the program just seems to break when I try to send a string from the string array. I've also tried things like saving a temp string such as:

String temp = stringArray[0];

but this also does not work. I am also unable to print the stringArray values outside of when they are initially created in the posted code block. So the print in that section works, but printing the strings anywhere else fails. Am I misunderstanding something about how globals or strings work? Does anyone have advice for a solution or better approach?


That will only send the very first character of the string.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.