c++ Arduino串行监视器给出了问号和框与我的输出

d8tt03nd  于 2023-06-25  发布在  其他
关注(0)|答案(1)|浏览(287)

我正在编写一个程序来加密给定的输入,并通过LoRa波发送密文,但我似乎被困在这一步。我使用的是Heltec LoRa ESP32,并包含了AES函数的mbedtls库。

  1. #include "mbedtls/aes.h"
  2. #include "heltec.h"
  3. #include <SPI.h>
  4. #define BAND 433E6 //setting the LoRa bands to 433 mhz
  5. mbedtls_aes_context aes;
  6. int counter = 0;
  7. unsigned char key[32] = "key"; // 256 bit - AES = 32 bytes for key
  8. unsigned char iv[16];
  9. unsigned char input [128] = "given AES plain text";
  10. unsigned char output[128];
  11. size_t input_len = 40;
  12. size_t output_len = 0;
  13. void setup() {
  14. Heltec.begin(true /*DisplayEnable Enable*/, true /*Heltec.Heltec.Heltec.LoRa Disable*/, true /*Serial Enable*/, true /*PABOOST Enable*/, BAND /*long BAND*/);
  15. //setup code to enable LoRa
  16. Serial.begin(115200); //establishing serial communication with esp32 and pc
  17. mbedtls_aes_setkey_enc( &aes, key, 256 );
  18. mbedtls_aes_crypt_cbc( &aes, MBEDTLS_AES_ENCRYPT, 48, iv, input, output ); // AES function from mbedtls library,
  19. }
  20. void loop() {
  21. Serial.print("Sending packet: ");
  22. Serial.println(counter);
  23. Serial.println((char*)output); //here is the issue
  24. // send packet
  25. LoRa.beginPacket();
  26. LoRa.print((char*)output);
  27. LoRa.print(counter);
  28. LoRa.endPacket();
  29. counter++;
  30. delay(5000);
  31. }

输出给出了一个包含(我假设)特殊字符的密文,当我看Arduino串行监视器时,它显示了一堆反向问号和带有正常字符的框。

  1. Serial.println((char*)output);

Arduino IDE中是否有打印方法可以显示这些特殊字符?

ecfdbz9o

ecfdbz9o1#

  1. Serial.begin(115200);

串行监视器波特率值应与上述值相同。

相关问题