Go Down

Topic: client.println() help (Read 678 times) previous topic - next topic


What is the difference here and how can I make the second method work correctly?

This works as expected:
Code: [Select]
  client.println("2|on+250|666|Motion Alarm|sensorPin 3");

This does not (some if statements, etc removed):
Code: [Select]

   String y = "on";  // or "off"
   int sPin = 2; // or 1

   String outPut = sPin; outPut.concat("|"); outPut.concat(y);
                    outPut.concat("|"); outPut.concat("666"); outPut.concat("|");
                    outPut.concat("Motion Alarm"); outPut.concat("|"); outPut.concat("sensorPin ");
                    outPut.concat(x);  // yes, the number of concats could be greatly reduced.

   client.println(outPut);  // this apparently gets sent as "chunks"

More info.
   Serial.println() output looks the same using both methods.

Obviously, I'm no programmer.
Thank you in advanced for any help.


Which version of the IDE/String library are you using?


You forgot to mention the output the code produced:

What prints code 1:

What prints code 2:
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)


I"m using the arduino 0022 IDE for mac.

More background.

  I'm using the Arduino UNO + Ethernet Shield.  The UNO monitors (currently) two sensors (simple normally open relays).  When a sensor is "triggered" a TCP signal is sent to a server to Activate the "Alarm".  After a bit of time a signal is sent to deActivate the "Alarm".

  So, Pin 2 and Pin 3 correlate to Zone 1 and Zone 2 on the server.  My hope is to reduce code and build the string instead of having to hard code the client.println() strings.  Making it much easier to add/remove sensors.

  On the server side, there is a perl daemon listening on the other side awaiting connections.
  Some more coding has further reviled.

  What I don't understand is why does this work:
Code: [Select]
// works awesome! but not what I want.
     client.println("2|on+250|666|Motion Alarm|sensorPin 3");

  and this does not work (meaning perl daemon cant read it correctly):
Code: [Select]
// does not work :(
    String outPut = "2|on+250|666|Motion Alarm|sensorPin 3";



What I don't understand is why does this work:
  and this does not work (meaning perl daemon cant read it correctly):

Have you verified that the client.println() method actually has an overload for Strings?

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131