cpainchaud / RFLink32

RFLink for ESP, with MQTT client
Other
135 stars 46 forks source link

Serial output does not always use the proper line ending #3

Closed obones closed 3 years ago

obones commented 3 years ago

Using the latest sources, here is the output I get on the serial line:

Trying to connect WIFI SSID netssid. A status will be given whenever it occurs.
Connected to AP!
SSID: netssid
             BSSID: 01:23:45:67:89:AB
                                     Channel: 1
Auth mode: 4
RFM69 initialized with Freq = 433.92
                                    Radio pin RF_RX_VCC :       27
Radio pin RF_RX_GND :   13
Radio pin RF_RX_NA :    14
Radio pin RF_RX_DATA :  25
Radio pin RF_TX_VCC :   4
Radio pin RF_TX_GND :   16
Radio pin RF_TX_DATA :  25
20;00;RFLink_ESP;VER=5.1;
Starting WebServer... OK
WiFi Client has received a new IP: 1.2.3.4
                                          Message arrived [Serial] 10;RFUDEBUG=ON;
20;01;RFUDEBUG=ON;

This comes from the fact that those new messages use Serial.printf with a trailing \n instead of using \r\n. However, to avoid constant proliferation, I believe it is much more recommended to use Serial.println wherever needed, which is what I have done in the following patch:

diff --git a/RFLink/10_Wifi.cpp b/RFLink/10_Wifi.cpp
index f8dd42b..453b410 100644
--- a/RFLink/10_Wifi.cpp
+++ b/RFLink/10_Wifi.cpp
@@ -313,8 +313,9 @@ void eventHandler_WiFiStationConnected(WiFiEvent_t event, WiFiEventInfo_t info)
     for(int i=0; i<info.connected.ssid_len; i++){
       Serial.print((char) info.connected.ssid[i]);
     }
+    Serial.println();

-    Serial.print("\nBSSID: ");
+    Serial.print("BSSID: ");
     for(int i=0; i<6; i++){
       Serial.printf("%02X", info.connected.bssid[i]);

@@ -322,8 +323,9 @@ void eventHandler_WiFiStationConnected(WiFiEvent_t event, WiFiEventInfo_t info)
         Serial.print(":");
       }
     }
+    Serial.println();

-    Serial.print("\nChannel: ");
+    Serial.print("Channel: ");
     Serial.println(info.connected.channel);

     Serial.print("Auth mode: ");
@@ -332,7 +334,8 @@ void eventHandler_WiFiStationConnected(WiFiEvent_t event, WiFiEventInfo_t info)
 }

 void eventHandler_WiFiStationGotIp(WiFiEvent_t event, WiFiEventInfo_t info) {
-  Serial.printf("WiFi Client has received a new IP: %s\n", WiFi.localIP().toString().c_str());
+  Serial.printf("WiFi Client has received a new IP: %s", WiFi.localIP().toString().c_str());
+  Serial.println();
   reconnectServices();
 }

@@ -350,12 +353,13 @@ void eventHandler_WiFiStationConnected(const WiFiEventSoftAPModeStationConnected
   Serial.print("SSID: ");
   Serial.println(WiFi.SSID());

-  Serial.print("\nChannel: ");
+  Serial.print("Channel: ");
   Serial.println(WiFi.channel());

 }
 void eventHandler_WiFiStationGotIp(const WiFiEventStationModeGotIP& evt) {
-  Serial.printf("WiFi Client has received a new IP: %s\n", WiFi.localIP().toString().c_str());
+  Serial.printf("WiFi Client has received a new IP: %s", WiFi.localIP().toString().c_str());
+  Serial.println();
   reconnectServices();
 }
 void eventHandler_WiFiStationDisconnected(const WiFiEventStationModeDisconnected& evt) {
diff --git a/RFLink/11_Config.cpp b/RFLink/11_Config.cpp
index c0e6462..20a0816 100644
--- a/RFLink/11_Config.cpp
+++ b/RFLink/11_Config.cpp
@@ -609,12 +609,13 @@ void executeCliCommand(const char *cmd) {
       String msg;
       pushNewConfiguration(root, msg, false);
       if(msg.length() > 0) {
-          Serial.printf("Some warning/errors occured while trying to SET config from CLI:\n");
+          Serial.println("Some warning/errors occured while trying to SET config from CLI:");
           Serial.println(msg.c_str());
       }
     }
     else {
-      Serial.printf("Error : unknown command '%s'\n", command.c_str());
+      Serial.printf("Error : unknown command '%s'", command.c_str());
+      Serial.println();
     }

   }
diff --git a/RFLink/1_Radio.cpp b/RFLink/1_Radio.cpp
index 46c0954..b07e5fc 100644
--- a/RFLink/1_Radio.cpp
+++ b/RFLink/1_Radio.cpp
@@ -110,6 +110,7 @@ void refreshParametersFromConfig() {
     auto new_hardware_id =  hardwareIDFromString(item->getCharValue());
     if( new_hardware_id == HardwareType::HW_EOF_t ) {
       Serial.printf("Unsupported radio hardware name '%s' was provided, falling to default generic receiver!", item->getCharValue());
+      Serial.println();
       changesDetected = true;
       hardware = HardwareType::HW_basic_t;
       item->setCharValue(hardwareNames[hardware]);
@@ -320,6 +321,7 @@ void set_Radio_mode(States new_State)
     set_Radio_mode_RFM69(new_State);
   else
     Serial.printf("Error while trying to switch Radio state: unknown hardware id '%i'", new_State); 
+    Serial.println();
 }

 void setup() {
@@ -408,7 +410,8 @@ void set_Radio_mode_RFM69(States new_State)
       radio.reset();
       radio.initialize();
       radio.setFrequency(433920000);
-      Serial.printf("RFM69 initialized with Freq = %.2f\n", (double)radio.getFrequency()/1000000);
+      Serial.printf("RFM69 initialized with Freq = %.2f", (double)radio.getFrequency()/1000000);
+      Serial.println();
       //Serial.print("Temp = "); Serial.println(radio.readTemperature());
       if(hardware == HardwareType::HW_RFM69HCW_t)
         radio.setHighPower(true);
diff --git a/RFLink/2_Signal.cpp b/RFLink/2_Signal.cpp
index 05c2332..ac0f37c 100644
--- a/RFLink/2_Signal.cpp
+++ b/RFLink/2_Signal.cpp
@@ -703,7 +703,7 @@ void RawSendRF(RawSignalStruct *signal) {
         //Serial.println(cmd+commaIndex);
       }

-      //Serial.printf("Now reading Json to find signal properties");
+      //Serial.println("Now reading Json to find signal properties");

       auto root = json.as<JsonObject>();
       JsonArrayConst pulsesJson = root.getMember("pulses");
@@ -713,19 +713,22 @@ void RawSendRF(RawSignalStruct *signal) {
       for(JsonVariantConst pulse : pulsesJson) {
           index ++;
           signal.Pulses[index] = pulse.as<signed long int>();
-          //Serial.printf("Pulse=%i\n",signal.Pulses[index]);
+          //Serial.printf("Pulse=%i",signal.Pulses[index]);
+          //Serial.println();
       }

       signal.Repeats = root.getMember("repeat").as<signed int>();
       signal.Delay = root.getMember("delay").as<signed int>();

       Serial.printf("** sending RF signal with the following properties: pulses=%i, repeat=%i, delay=%i... ", signal.Number, signal.Repeats, signal.Delay);
+      Serial.println();
       RawSendRF(&signal);
       Serial.println("done");

     }
     else {
-      Serial.printf("Error : unknown command '%s'\n", command.c_str());
+      Serial.printf("Error : unknown command '%s'", command.c_str());
+      Serial.println();
     }

   }

Also available as a diff file here: println.zip

With this, I get a much cleaner output in the serial console

cpainchaud commented 3 years ago

fixed