GrumpyOldPizza / ArduinoCore-stm32l0

Arduino Core for STM32L0
125 stars 67 forks source link

Hex or Alpha #184

Closed hpssjellis closed 3 years ago

hpssjellis commented 3 years ago

I will eventually stop asking questions!

Most LoRa code converts message strings to HEX, I have no problem doing that but your library seems fine with Alpha except I am having some issues looping through:

   for (int i = 0; i < LoRaRadio.parsePacket(); i++) {
        Serial.print((char)LoRaRadio.read());
   } 

whereas the following works fine: ( Also LoRaRadio.parsePacket() seems to read only once then reset to zero)

    Serial.print((char)LoRaRadio.read());
    Serial.print((char)LoRaRadio.read());
    Serial.print((char)LoRaRadio.read());
    Serial.print((char)LoRaRadio.read());

Here is how most other libraries deal with Alphas. Which I am fine doing just wondering if you have an easier suggestion.

void loop() {
  Serial.println();
  Serial.println("Enter a message to send to network");
  Serial.println("(make sure that end-of-line 'NL' is enabled)");

  while (!Serial.available());
  String msg = Serial.readStringUntil('\n');

  Serial.println();
  Serial.print("Sending: " + msg + " - ");
  for (unsigned int i = 0; i < msg.length(); i++) {
    Serial.print(msg[i] >> 4, HEX);
    Serial.print(msg[i] & 0xF, HEX);
    Serial.print(" ");
  }
  Serial.println();

  int err;
  modem.beginPacket();
  modem.print(msg);
  err = modem.endPacket(true);
  if (err > 0) {
    Serial.println("Message sent correctly!");
  } else {
    Serial.println("Error sending message :(");
    Serial.println("(you may send a limited amount of messages per minute, depending on the signal strength");
    Serial.println("it may vary from 1 message every couple of seconds to 1 message every minute)");
  }
  delay(1000);
  if (!modem.available()) {
    Serial.println("No downlink message received at this time.");
    return;
  }
hpssjellis commented 3 years ago

No Worries, Serial.print is messing things up and just needs to be on a timer. All good now.