Skip to content
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

Added custom mac addresses + dhcp renew, longer tcp ack retransmit timeout, improved error handling. #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

BlakeGarner
Copy link

Added support for:

  • begin(byte *mac) {...} lets you specify your own MAC address [begin() is still supported]
  • Fix to not send "Content-Type" in GET requests.
  • Close connection if data size error, so it can restart gracefully.
  • Added maintain() method that should be called periodically to refresh DHCP settings.
  • Retransmission Time (ie time to retransmit if receive no TCP ACK) set to 4s, default too short.

+ begin(byte *mac) {...} lets you specify your own MAC address [begin() is still supported]
+ Fix to not send "Content-Type" in GET requests.
+ Close connection if data size error, so it can restart gracefully.
+ Added maintain() method that should be called periodically to refresh DHCP settings.

Signed-off-by: BlakeGarner <[email protected]>
@wolfeidau
Copy link

Hey what was the reason for the custom mac address?

Is this a common thing to need to override on arduino?

@BlakeGarner
Copy link
Author

Hey,
The W5100-based Ethernet shield on Arduino does not have a hardware-allocated MAC address - it must be set in code. The arduino-ninja-blocks library had a single mac hard-coded in - which is fine for prototyping, but problematic for long-term use, particularly if two or more devices were going to be deployed on the same LAN utilising this library.

@wolfeidau
Copy link

Ahh just reviewing the examples on the Arduino site.

http://arduino.cc/en/Tutorial/WebClient

Has a note in the code associated with the mac address.

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

Given this is labeled a library we should certainly enable this to be overridden.

Previously single HTTP GET or POST messages were broken up across
multiple TCP packets. While okay, it did put additional load on the SPI
and Ethernet interfaces and could be fixed by preparing the entire
message ahead of time in a local buffer.
This did require some rearrangement of how httppost and ninjaMessage
were run, and a buffer (448 bytes).
The extra memory used by the buffer has mostly been reclaimed through
other optimisations:
- Fixed strings use program (flash) memory instead of SRAM.
- Build the JSON data on the fly within the packet buffer, rather than
in its own.
- Use the same buffer for reading and sending packets to/from the W5100,
as they can't occur at the same time.

Other Changes:
- strcat has a O(n) penalty to find the end of the string every time it
is run. Removed it in favour of strcpy and keeping track of where the
pointer is up to.
- Removed a few redundant or unused library or variable declarations.
- Added a few extra Serial.prints to help debug connection errors in the
future.
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