user84823: Im having trouble in sending float number and multiple float numbers.
Im currently working on project matlab and arduino mkr1000. The situation is that i want to send float number and multiple float numbers through communication(which in client.available() code) and view it in Serial Monitor. I have been searching throughout the internet but unfortunately could not receive it. The more i read the more confused i became. Im new to this environment. I do need consider bitshifting right?. Is there any similar examples and guidances from others would be really highly appreciated. Thank you.
Arduino Ide
    /* Latest Progress of the Project*/
#include <SPI.h>
#include <WiFi101.h>

// sensitive data placed in arduino_secrets.h
#include "arduino_secrets.h"
char ssid[] = SECRET_SSID; // name wifi
char pass[] = SECRET_PASS; // password
int status = WL_IDLE_STATUS; // status of wifi

// variables used
float value;

IPAddress ipserver(192, 168, 1, 109); // home wifi ip address

// initialize the client library
WiFiClient client;

void setup()
{
  // initialize serial and wait for port to open:
  Serial.begin(115200);
  Serial.println();
  Serial.println();
  Serial.println("Attempting to connect to WPA network...");
  Serial.print("SSID:");
  Serial.println(ssid);

  // attempt to connect to WiFi network:
  while (status != WL_CONNECTED)
  {
    // will keep trying until connected
    Serial.print("Attempting to connect to network: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds(enough time) for connection:
    delay(10000);
  }

  // if you're connected now, so print the data status:
  Serial.println("You're connected to the network");
  Serial.println("------------------------------------");
  Serial.println("Hi FYP63333 Group");
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
  Serial.println("------------------------------------");
  Serial.println("\nStarting connection to server...");
}

void loop()
{
  // Client connect or not connect in serial monitor:
  if (!client.connect(ipserver, 1234))
  {
    // if you didnt't get a connection to the server:
    Serial.println("Can't connect to server, try again.");
    delay(5000);
    return;
  }
  else
  {
    // if you get connection to the server:
    Serial.println("Connected to server!!!");
    Serial.println("MATLAB READY");
    //client.println("Hello from MKR1000");
  }

  // If there are incoming bytes available from the server, read and print them
  // Read all the lines of the reply from server and print them inside Serial Monitor:
  Serial.println();
  Serial.println("Incoming and receiving data from remote server:");
  while (client.connected() || client.available() || Serial.available())
  {
    while (Serial.available())
    {
      char data;
      data = Serial.read();
      if (client.connected())
      {
        client.print(data);
      }
    }
    while (client.available())
    {

      //------------------main-code(works)--------------for string//
      char ch = static_cast<char>(client.read());
      Serial.println(ch);
    }
  }

  // if the server's disconnected, stop the client:
  if (!client.connected())
  {
    Serial.println();
    Serial.println("Disconnecting from the server.");
    client.stop();
  }
}

Matlab code
clear; 
clc;
%% Connecting matlab and Arduino IDE(TCP/IP Server)
t = tcpserver("192.168.1.109",1234);
t.ByteOrder = "big-endian";


user4143: Sending numerical values between systems is fraught with difficulty. Not only do you have to ensure that both ends agree on the size of the data (16 bit vs 32 bit ints, float vs double, etc) but that the byte ordering is handled correctly. On top of that is knowing where a number is in the stream of data. With nothing to delimit each value (and when you have 8 bits of communication width and 8 bits of data there's no room for "out of band" control signals) yo have no way of knowing which byte in the data stream corresponds to which byte in a value's raw data.
It's far better to encode the data into some other format that leaves you room to add delimiting control signals and has a predefined machine-agnostic data format.
The simplest encoding: ASCII. Simply "print" the numbers as text with the precision you desire (number of decimal places) as one number per line. Then on the Arduino you can read text data a line at a time then use the internal float conversion routines to turn that data into an actual floating point value again.
Some references:

Reading Serial on the Arduino - a blog post by me, also applicable to TCP/IP communication
String::toFloat() - Converting a String object to a floating point value
strtof() - Convert a C string to a floating point value


84823: <p>Im having trouble in sending float number and multiple float numbers.
Im currently working on project matlab and arduino mkr1000. The situation is that i want to send float number and multiple float numbers through communication(which in client.available() code) and view it in Serial Monitor. I have been searching throughout the internet but unfortunately could not receive it. The more i read the more confused i became. Im new to this environment. I do need consider bitshifting right?. Is there any similar examples and guidances from others would be really highly appreciated. Thank you.</p>
<p>Arduino Ide</p>
<pre><code>    /* Latest Progress of the Project*/
#include &lt;SPI.h&gt;
#include &lt;WiFi101.h&gt;

// sensitive data placed in arduino_secrets.h
#include &quot;arduino_secrets.h&quot;
char ssid[] = SECRET_SSID; // name wifi
char pass[] = SECRET_PASS; // password
int status = WL_IDLE_STATUS; // status of wifi

// variables used
float value;

IPAddress ipserver(192, 168, 1, 109); // home wifi ip address

// initialize the client library
WiFiClient client;

void setup()
{
  // initialize serial and wait for port to open:
  Serial.begin(115200);
  Serial.println();
  Serial.println();
  Serial.println(&quot;Attempting to connect to WPA network...&quot;);
  Serial.print(&quot;SSID:&quot;);
  Serial.println(ssid);

  // attempt to connect to WiFi network:
  while (status != WL_CONNECTED)
  {
    // will keep trying until connected
    Serial.print(&quot;Attempting to connect to network: &quot;);
    Serial.println(ssid);
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds(enough time) for connection:
    delay(10000);
  }

  // if you're connected now, so print the data status:
  Serial.println(&quot;You're connected to the network&quot;);
  Serial.println(&quot;------------------------------------&quot;);
  Serial.println(&quot;Hi FYP63333 Group&quot;);
  Serial.print(&quot;SSID: &quot;);
  Serial.println(WiFi.SSID());
  Serial.println(&quot;------------------------------------&quot;);
  Serial.println(&quot;\nStarting connection to server...&quot;);
}

void loop()
{
  // Client connect or not connect in serial monitor:
  if (!client.connect(ipserver, 1234))
  {
    // if you didnt't get a connection to the server:
    Serial.println(&quot;Can't connect to server, try again.&quot;);
    delay(5000);
    return;
  }
  else
  {
    // if you get connection to the server:
    Serial.println(&quot;Connected to server!!!&quot;);
    Serial.println(&quot;MATLAB READY&quot;);
    //client.println(&quot;Hello from MKR1000&quot;);
  }

  // If there are incoming bytes available from the server, read and print them
  // Read all the lines of the reply from server and print them inside Serial Monitor:
  Serial.println();
  Serial.println(&quot;Incoming and receiving data from remote server:&quot;);
  while (client.connected() || client.available() || Serial.available())
  {
    while (Serial.available())
    {
      char data;
      data = Serial.read();
      if (client.connected())
      {
        client.print(data);
      }
    }
    while (client.available())
    {

      //------------------main-code(works)--------------for string//
      char ch = static_cast&lt;char&gt;(client.read());
      Serial.println(ch);
    }
  }

  // if the server's disconnected, stop the client:
  if (!client.connected())
  {
    Serial.println();
    Serial.println(&quot;Disconnecting from the server.&quot;);
    client.stop();
  }
}
</code></pre>
<p>Matlab code</p>
<pre><code>clear; 
clc;
%% Connecting matlab and Arduino IDE(TCP/IP Server)
t = tcpserver(&quot;192.168.1.109&quot;,1234);
t.ByteOrder = &quot;big-endian&quot;;
</code></pre>
 4143: <p>Sending numerical values between systems is fraught with difficulty. Not only do you have to ensure that both ends agree on the size of the data (16 bit vs 32 bit ints, float vs double, etc) but that the byte ordering is handled correctly. On top of that is knowing <em>where</em> a number is in the stream of data. With nothing to delimit each value (and when you have 8 bits of communication width and 8 bits of data there's no room for &quot;out of band&quot; control signals) yo have no way of knowing which byte in the data stream corresponds to which byte in a value's raw data.</p>
<p>It's far better to encode the data into some other format that leaves you room to add delimiting control signals and has a predefined machine-agnostic data format.</p>
<p>The simplest encoding: ASCII. Simply &quot;print&quot; the numbers as text with the precision you desire (number of decimal places) as one number per line. Then on the Arduino you can read text data a line at a time then use the internal float conversion routines to turn that data into an actual floating point value again.</p>
<p>Some references:</p>
<ul>
<li><a href="https://majenko.co.uk/blog/our-blog-1/reading-serial-on-the-arduino-27" rel="nofollow noreferrer">Reading Serial on the Arduino</a> - a blog post by me, also applicable to TCP/IP communication</li>
<li><a href="https://www.arduino.cc/reference/en/language/variables/data-types/string/functions/tofloat/" rel="nofollow noreferrer">String::toFloat()</a> - Converting a <code>String</code> object to a floating point value</li>
<li><a href="https://www.cplusplus.com/reference/cstdlib/strtof/" rel="nofollow noreferrer">strtof()</a> - Convert a C string to a floating point value</li>
</ul>
