TCP client baud rate to server & code

I’m creating a server by hotspotting my computer (haven’t done it yet), but in the references it says “Server.begin(80);” Does that mean that the baud rate is max 80 or can it be faster like 9600. However, I only realized now that the 9600 baud refers to serial transmission, and I’m doing it wirelessly. “serial.begin(9600)”

Also, if you see anything wrong in my code, let me know, still trying to get the server up before checking the code.

Here is my code:

  int sensor1 = A1;
  int sensorV = 0;
  char sensorStr[64];

  TCPClient2 client;
  client.connect(ip, port); //change


 void setup()
 {
  Serial.begin(9600);
  Server.begin(80);
  
   pinMode(sensor1, INPUT);
   Particle.variable("sensorV", sensorStr);
   
   
  while(!Serial.available()) Particle.process();

  Serial.println("connecting...");

  if (client.connect(server, 80))
  {
    Serial.println("connected");  //change
    client.println();
  }
  else
  {
    Serial.println("connection failed");
  }
}

 void loop()
 {
    
    if (client.available()) 
        {
    sensorV = analogRead(sensor1);
    snprintf(sensorStr, sizeof(sensorStr), "%d", sensorV);
    delay(2);
    client.print(sensorStr);
        }
        
    if (!client.connected()) 
    {
        Serial.println();
        Serial.println("disconnecting.");
        client.stop();
        for(;;);
    }

}

Does this function even work? :smiley:

found it in the references. So it should. But not sure if I can increase it.

But wouldn’t you need need something like:

TCPServer server = TCPServer(port);
as per https://docs.particle.io/reference/firmware/photon/#tcpserver ?

Also the docs clearly says: Parameters: port: the port to listen on (int) (which refers to the question about the number 80 that is unclear to you)

2 Likes

Ahh ok, makes sense. And I’d think to put that in my server code and not my client (particle) code. Also, could a serial command be used for wireless transmission, or solely for wired connection?

What do you mean by that?
But the way I understand the question: No - not per se.

server and Serial are objects of a different kind which might share certain commands (due to shared ancestors in the OOP meaning of the term) but do act quite differently.

To illustrate:
Your house and your car are completely different objects but both share some properties like an “internal key hole” (flat door or ignition key).
You can insert a key in both, you can turn both, but the effect of both methods is quite different.
And you won’t be able to use an accelerate() method on your house or run_a_bath() in your car (I guess ;-))

Then what command would do send data by TCP but wirelessly?

If you look at the methods TCPClient provides plus the methods provided by the “ancestor” class Stream, you should get pretty much what you need.

But as said, these are no “serial commands” but Serial has - just like TCPClient - also inherited from Stream which provided the methods for both (and other) classes.