Skip to content

added server mode to StandardFirmataEthernet #375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2017

Conversation

MJPees
Copy link
Contributor

@MJPees MJPees commented Jul 9, 2017

server mode implemented.
For server mode remote_ip, remote_host and remote_port should not be
defined.
Instead the server_port has to be defined.

@@ -55,7 +56,9 @@ YunClient client;

// STEP 3 [REQUIRED]
// Replace with the port that your server is listening on
// for client mode comment out remote_port / for server mode comment out server_port
#define remote_port 3030
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be simplified by renaming remote_port to network_port and then using that for both client and server applications.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The update the comment to:

// Replace with the port that your client or server is listening on.

@@ -3,8 +3,9 @@
*
* You must configure your particular hardware. Follow the steps below.
*
* Currently StandardFirmataEthernet is configured as a TCP client. An
* option to configure as a server may be added in the future.
* Currently StandardFirmataEthernet is configured as a TCP client.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change this text to:
"By default, StandardFirmataEthernet is configured as a TCP client. To configure as a TCP server, see STEP 2."

Then update STEP 2 to read as follows:

// STEP 2 [REQUIRED for all boards and shields]
// TCP Client configuration:
// To configure your board as a TCP client, set the IP address of the server you want to connect to.
// TCP Server configuration:
// To configure your board as a TCP server, comment out the following line and also ensure that
// remote_host is also commented out.

stream.maintain(Ethernet.localIP());
#else
stream.maintain();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to call stream.maintain() here since it is already called on each iteration of loop when firmata.available is called. However, you may need to copy the maintain(IPAddress local) method from EthernetClientStream to EthernetServerStream and then leave this block of code as it originally was. You should test this however to ensure there are not side effects.

@MJPees
Copy link
Contributor Author

MJPees commented Jul 9, 2017

I think the parameter client is useless at initialization of EthernetServerStream.h => removed it.
Thanks so far!


#if !defined remote_ip && !defined remote_host
#ifdef local_ip
EthernetServerStream stream(client, local_ip, network_port);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the client parameter here and on line 125. Then make sure StandardFirmataEthernet compiles when configured for TCP server.

@MJPees
Copy link
Contributor Author

MJPees commented Aug 1, 2017

Tested on Arduino Ethernet and Arduino Mega/ Ethernet shield

@soundanalogous
Copy link
Member

I finally got around to thoroughly testing this today and it's working without issue. However, one addition would be helpful. Please add the following 3 lines at the end of the initTransport() function in StandardFirmataEthernet.ino (just after the DEBUG_PRINT("connecting...") line, but add a space in-between):

DEBUG_PRINT("IP Address: ");
IPAddress ip = Ethernet.localIP();
DEBUG_PRINTLN(ip);

That will print the local IP address when debugging is enabled, which is helpful for the user to know what the board's IP address is when configured as a TCP server.

After that, please squash all commits to a single commit. Then this PR will be ready to merge. Thanks for all the work so far!

server mode implemented.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants