最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

JSON Construction Issue - Arduino Nano 33 IoT Blocks on StaticJsonDocument Usage - Stack Overflow

programmeradmin1浏览0评论

I'm working on an SSI (Self-Sovereign Identity) system with an Arduino Nano 33 IoT. The device receives credential definition chunks successfully but blocks when trying to process them. The device receives 15 chunks correctly and sends acknowledgments, but then fails when trying to construct JSON messages with the received data. Here's my current Arduino code:

    void createAndSendCredentialRequest() {
        Serial.println("INIZIO createAndSendCredentialRequest");
        StaticJsonDocument<1024> chunk_msg;
    
        for(int i = 0; i < 15; i++) {
          chunk_msg["type"] = "CRED_DEF_CHUNK_RESPONSE";
          chunk_msg["chunk_num"] = i + 1;
          chunk_msg["total_chunks"] = 15;
          chunk_msg["data"] = device.credDefChunks[i];
          chunk_msg["master_secret_id"] = device.master_secret_id;
          chunk_msg["did"] = device.did;
          String jsonString;

          String messageString;
          serializeJson(chunk_msg, messageString);
          Serial.print("Message è: ");
          Serial.println(messageString);
          sendMessage(messageString);
    

        }
    
        device.processing_cred_def = false;
        device.cred_def_received = false;
    }

Serial Monitor output shows successful chunk reception but fails afterward:

Received: {"type": "CRED_DEF_CHUNK", "chunk_num": 14, "total_chunks": 15, "size": 360,
"data":"718503585250037822403195906791987770827989377673766710927877102237103196038635278147404613685704054372383357585590792782218119406390083040714121687371454959411282176701251076026696578442412510004258312404573278161919162741577306180457184928925433424961279072160693404514782996475508551719082756929166986899461219726648675644565109901718185167235337112412204830"} Sent: {"type":"CHUNK_ACK","chunk_num":14} Received: {"type": "CRED_DEF_CHUNK", "chunk_num": 15, "total_chunks": 15, "size": 360, "data":"317181867653119323161422709328926219982823954320174528971914850099325924974517972398554946011174440619118760535768955600824827441145100151686701119940208639686181818756964161452236376789512299419782216381503574345070470\"}}}"}"} Sent: {"type":"CHUNK_ACK","chunk_num":15} Retry 1 Retry 2 Retry 3 Too many failed retry

Server side confirms successful sending:

Sending credential definition in chunks... Received ACK per chunk 1

Received ACK per chunk 15 Credential definition sent

Key issues:

Device successfully receives and acknowledges all chunks Blocks when trying to construct new JSON messages with StaticJsonDocument Each chunk is around 360 bytes The data field contains large numbers and escape characters

Questions:

Is the 1024-byte StaticJsonDocument size insufficient? Could the escape characters in the chunks be causing issues? What's the best way to handle large JSON construction on Arduino Nano 33 IoT?

What I've tried:

Direct string construction (still blocks) Adding delays between operations Different buffer sizes for StaticJsonDocument Debugging with Serial prints (shows blocking at first JSON field assignment)

Environment:

Arduino Nano 33 IoT ArduinoJson library WiFiNINA library

发布评论

评论列表(0)

  1. 暂无评论