Sketch won't "Serial.print"

Hi,

I’m having issues with a sketch not doing what I want it to. Since I knew this might happen, I included a bunch of Serial.print lines to see if I could figure out where it was going wrong, and so as to focus my efforts.

I have replicated my entire sketch below (it’s not very long) and there are a couple of points at which it should Serial.print but nothing appears in the Serial monitor during sketch run.

Obviously my sketch isn’t working, so if anyone has any pointers as to what’s going wrong too that would be very much appreciated. In terms of what the sketch is trying to achieve:

  1. Receive an input from somebody typing an instruction into their web browser. Eg, instruction “A110” would be sent by typing 192.168.0.155/?A110 into the web browser.
  2. Compile this into a string “A110”
  3. Send this (using the VirtualWire library) through RF to a receiver unit which will take the appropriate action.
#include <Ethernet.h>
#include <SPI.h>
#include <VirtualWire.h>
boolean reading = false;

////////////////////////////////////////////////////////////////////////
//CONFIGURE
////////////////////////////////////////////////////////////////////////
  byte ip[] = { 192, 168, 0, 155 };   //ip address to assign the arduino
  byte gateway[] = { 192, 168, 0, 1 }; //ip address of the gatewa or router

  //Rarly need to change this
  byte subnet[] = { 255, 255, 255, 0 };

  // if need to change the MAC address (Very Rare)
  byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

  EthernetServer server = EthernetServer(80); //port 80
////////////////////////////////////////////////////////////////////////

void setup(){
  //Pin 13 has LED connected to it, which we will light up during RF transmission

  pinMode(13, OUTPUT);


  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();
  
  vw_set_ptt_inverted(true); //
  vw_set_tx_pin(2);
  vw_setup(4000);// speed of data transfer Kbps
  
  
  
  
}

void loop(){

  // listen for incoming clients, and process qequest.
  checkForClient();

}

void checkForClient(){

  EthernetClient client = server.available();

  if (client) {

    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    boolean sentHeader = false;

    while (client.connected()) {
      if (client.available()) {

        if(!sentHeader){
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          sentHeader = true;
        }

        char buf[VW_MAX_MESSAGE_LEN];         //allocate space for the string
        char c =-1;                            // Where to store the character read
        byte index = 0;                       // Index into array; where to store the character
        
   if(reading && c == ' ') reading = false;
        if(c == '?') reading = true; //found the ?, begin reading the info

        if(reading){
          Serial.print(c);
                   
 
  
    {
        if(index < VW_MAX_MESSAGE_LEN - 1) // Where receipt is one less than the size of the array
        {
            c = client.read(); // Read a character
            buf[index] = c; // Store it
            index++; // Increment where to write next
        }
        else{
            
            buf[index] = '\0';   // Null terminate the string
            Serial.print(buf);   // Print the final string to the serial monitor
            index = 0;           //  set index back to zero ready for the next input string. 

        }
    }

               

      
           
            vw_send((uint8_t *)buf, strlen(buf));
            vw_wait_tx(); // Wait until the whole message is gone
            delay(1000);
            
   

        }

        if (c == '\n' && currentLineIsBlank)  break;

        if (c == '\n') {
          currentLineIsBlank = true;
        }else if (c != '\r') {
          currentLineIsBlank = false;
        }

      }
    }

    delay(1); // give the web browser time to receive the data
    client.stop(); // close the connection:

  } 

}

Stand by to kick yourself.

I can't see a Serial.begin() in your program

You have no Serial.begin(9600);

edit: Damn..... 11 seconds too slow on the buzzer there.

Thanks both, I'll try that - consider myself kicked! :astonished:

#include <Ethernet.h>

  EthernetServer server = EthernetServer(80); //port 80
////////////////////////////////////////////////////////////////////////

void setup(){
  //Pin 13 has LED connected to it, which we will light up during RF transmission

  pinMode(13, OUTPUT);

Not if you expect the Ethernet shield to work.

        char c =-1;                            // Where to store the character read
        byte index = 0;                       // Index into array; where to store the character
        
   if(reading && c == ' ') reading = false;
        if(c == '?') reading = true; //found the ?, begin reading the info

It makes no sense, to me, to assign a value to c, and then test if c has some other value(s).

        if(reading){
          Serial.print(c);

What do you supposed that printing a -1, as a char, is going to result in?

Please use Tools + Auto Format, and consistent placement of {, before posting code again.