Pages: [1]   Go Down
Author Topic: client.println() help  (Read 472 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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

   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.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 617
Posts: 49455
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13742
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You forgot to mention the output the code produced:

What prints code 1:

What prints code 2:
Logged

Rob Tillaart

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

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
// 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:
// does not work :(
    String outPut = "2|on+250|666|Motion Alarm|sensorPin 3";
    client.println(outPut);

   
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 617
Posts: 49455
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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?
Logged

Pages: [1]   Go Up
Jump to: