URI / Percent Encoder, useful for web server/clients.

Here is another tool I have whipped up for use in my project. You can see the previous Base64 Encoder here: http://forum.arduino.cc/index.php?topic=201007.0

This tool will take your input and make it safe for transmission via things like http URL’s. Here is a quick example.
URIEncoder is the class, it takes a print object, and an optional value of either: URI_STANDARD, URI_WWWFORM, or URI_ALL.

By default URI_STANDARD is used.

#include <URIEncode.h>

void setup() {
  Serial.begin( 9600 );

  URIEncoder u_Enc( Serial, URI_STANDARD );
  Serial.print( F("http://www.google.com/search?q=") );
  u_Enc.print( F( "how to use c++ operator []" ) );

This returns:


Using URI_WWWFORM you will get:


And finally using URI_ALL:


you can set/get the mode using the Mode function.

The files are attached and provided here for people not logged in:

#include "Arduino.h"

  class URIEncoder : public Print{
      URIEncoder( Print &p_Out, URI_MODE u_Mode = URI_STANDARD ) : Output( p_Out ), Mode( u_Mode ) {}
      size_t write( uint8_t u_Data );  //Derived from Print.
      URI_MODE URIMode( void ) { return ( URI_MODE ) Mode; }
      void URIMode( URI_MODE u_Mode ) { Mode = u_Mode; }
      Print &Output;
      char Mode;
#include "URIEncode.h"

#define URI_CHAR_COUNT  19

  '!', '*', '\'', '(', ')', ';', ':', '@', '&', '=', '+', '

Let me know what you think, I’m also planning to do up stream supporting equivalents for this and the base64 class.

URIEncode.h (556 Bytes)

URIEncode.cpp (685 Bytes), ‘,’, ‘/’, ‘?’, ‘#’, ‘[’, ‘]’, ’ ’

size_t URIEncoder::write( uint8_t u_Data )
 bool b_Found = false;
 if( Mode != URI_ALL ){

for( char c_Index = 0x00 ; c_Index < URI_CHAR_COUNT ; ++c_Index ){
  if( pgm_read_byte( URIChars + c_Index ) == u_Data )
	b_Found = true;

b_Found = true;
 if( b_Found ){
if( u_Data == ’ ’ && Mode == URI_WWWFORM )
 return Output.write( ‘+’ );

Output.write( '%' );
Output.print( u_Data, HEX );
return 0x03;

return Output.write( u_Data );

Let me know what you think, I'm also planning to do up stream supporting equivalents for this and the base64 class.

[URIEncode.h|attachment](upload://971IzAMypB7m1r74sg2FIphACxk.h) (556 Bytes)

[URIEncode.cpp|attachment](upload://kazBo1Nh3h19ftTN0wfEIHmYWvl.cpp) (685 Bytes)

That looks great! I'll have to give it a try once I get this wifi shield server stuff under control. It is good to see utilities for the ethernet and wifi shields starting to appear here on the forum.

Cheers Tim, I have just posted another one of my tools which may interest you, it is a CRC class for streams here: http://forum.arduino.cc/index.php?topic=202336.0

I have linked from that page a DualWriter, which may be useful for debugging purposes, or streaming data to the internet and an SD module at the same time.

Also there is a Base64 encoder, similar to this URI encoder, as in it works with a Print reference.

I will have many more to come soon!