Output to serial monitor

I am trying to get an output on a serial monitor, as I don’t know if wireless is working.

Is my syntax correct and in the right place to get an output of what is being transmitted. Its a Nano board with a HC-12 device.

Thanks

//HC-12 Momentary Button Receive

#include <SoftwareSerial.h>
SoftwareSerial mySerial(5, 6); // RX, TX


int ledPin = 13;

void setup()
{
  mySerial.begin(9600);
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
}

void loop()
{

  if (mySerial.available() > 3)
  {
    int input = mySerial.parseInt();//

    Serial.println(input); // TRY TO GET DATA RECEIVED ON SERIAL MONITOR

    if (input == 1001) //if on code is received
    {
      digitalWrite(ledPin, HIGH);//turn LED on
    }
    if (input == 1002) //if off code is received
    {
      digitalWrite(ledPin, LOW);//turn LED off
    }
  }
  mySerial.flush();//clear the serial buffer for unwanted inputs

  delay(20);//delay little for better serial communication

}
mySerial.flush();//clear the serial buffer for unwanted inputs

Nope, flush() is a blocking function that waits until all outgoing serial bytes have been sent. It has nothing to do with serial input data.

for what you want to do wrt flushing the receive buffer, you can use this or something like it.

while(Serial.available())
(void) Serial.read();

Thanks Power_Broker, just took that line out but still no wireless.

I added in 2 statements in the code, only one reads "NO WIRELESS" so it looks like the HC-12 module has died or the Nano misbehaving or the Transmit end. I can see the transmit Nano's led on pin 13 flickering when transmitting so I guess it's more the receiving end.

Thanks for your help. All the best for 2017

Sorry, forgot to add code.

Thanks wgOz, I put your line of code in as well, so now I get my monitor saying

TISDEAD
EXTRATESTDEAD
NO WIRELESS

repeated. So does your code mean I have wireless coming in but its corrupted, or is it saying no wireless?

//HC-12 Momentary Button Receive

#include <SoftwareSerial.h>
SoftwareSerial mySerial(5, 6); // RX, TX


int ledPin = 13;

void setup()
{
  mySerial.begin(9600);
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
}

void loop()
{

while(Serial.available())
  (void) Serial.read();{
    Serial.println("TISDEAD");
  }

  if (mySerial.available() > 3)
  {
    int input = mySerial.parseInt();//
    Serial.println(input);
    Serial.println("EXTRATESTDEAD");
    delay (10000);
    
    if (input == 1001) //if on code is received
    {
      digitalWrite(ledPin, HIGH);//turn LED on
    }
    if (input == 1002) //if off code is received
    {
      digitalWrite(ledPin, LOW);//turn LED off
    }
  }

  Serial.println("NO WIRELESS");
  delay (10000);
  //mySerial.flush();//clear the serial buffer for unwanted inputs

  //delay(20);//delay little for better serial communication

}

my bad. change Serial to mySerial in the code I gave you.
you mustn't use it unconditionally in every execution of loop() either.

Thanks again. So just to confirm, would I only get something caught in the code if there was serial being received?

Regards

a complete rcv buffer flush should only be done under the most dire circumstances.
flushed data will typically never be processed by any other code.

try putting this at the top of loop();
if you ever get any data at all, you should get the message

if (0 != mySerial.available())
{
Serial.println(“data rcvd from HC-12”);
}

for what you want to do wrt flushing the receive buffer, you can use this or something like it.

while(Serial.available())
(void) Serial.read();

Be sure to put that in a function called throwAwayRandomAmountsOfUnreadData(), and call it where needed.

Be sure to explain WHY you want to do that. Doing that is almost NEVER the right thing to do.

Sorry for late reply, thanks both.

That line of code appeared in an article for using the HC-12 TX/RX. I will look at putting it in Paul as you say and thanks wgOz for explaining bit more

I think my RF board has died as every other check proves negative to being anything else.

Happy New Year all.