Show Posts
Pages: 1 ... 50 51 [52] 53 54 ... 142
766  Using Arduino / Networking, Protocols, and Devices / Re: URI Encoder, useful for web server/clients. on: December 02, 2013, 10:36:02 am
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!
767  Development / Other Software Development / CRC32 for Streams ( Ethernet, Serial, Wire, SoftwareSerial,...) on: December 02, 2013, 10:28:12 am
Hi all, I have a new piece of code to post.
This library can calculate a running CRC32 on a stream object.

Here are some other objects I have recently worked on, these are all part of a new library I'm planning to release.
Dual Writer
Base64Writer
URI Encoder

Below is the test code I wrote for it. The code will take anything and on a new line or carriage return the CRC of what has streamed in & out will be printed.

Like the tools posted above, they take a reference to a Print or Stream object, in this example, I use Serial.

The main functions ( apart from the print functionality ) are:
  • getCRC
  • resetCRC

    Each one takes a value specifying the CRC to use. The options are CRC_INPUT and CRC_OUTPUT

    This library is built off the CRC32 code I found here, linked from here.

    Test code for StreamCRC:
    Code: (test.ino)
    #include <StreamCRC.h>

    StreamCRC s_CRC( Serial );

    void setup(){
      Serial.begin( 9600 );
      Serial.println( F("Type anything to get started, on a new line or carriage return the CRC of what has streamed in & out will be printed.") );
    }

    void loop(){

      if( s_CRC.available() > 0x00 ){

        switch( s_CRC.peek() ){
        
          case '\r':
          case '\n':
          
            //Only print CRC if something has been recieved other than a new line char.
            if( s_CRC.getCRC( CRC_INPUT ) != 0 ){
              
              Serial.print( "\r\nOUT CRC: " );
              Serial.println( s_CRC.getCRC( CRC_OUTPUT ), HEX );
              s_CRC.print( "IN CRC: " );
              s_CRC.println( s_CRC.getCRC( CRC_INPUT ), HEX );
            }
            s_CRC.read();
            s_CRC.resetCRC( CRC_OUTPUT );
            s_CRC.resetCRC( CRC_INPUT );
            break;
        
          default:
            s_CRC.write( s_CRC.read() );
        }
      }
    }

    A test typing HELLO printed a CRC verifyable with PHP.
    Quote
    Type anything to get started, on a new line or carriage return the CRC of what has streamed in & out will be printed.
    HELLO
    OUT CRC: C1446436
    IN CRC: C1446436

    I will add the code here for people not logged on, also the files are attached.

    Code: (StreamCRC.h)
    #include "Arduino.h"

    #ifndef HEADER_CRCSTREAM
      #define HEADER_CRCSTREAM
      
      enum CRC_STREAM_ID{ CRC_INPUT, CRC_OUTPUT };
      
      class StreamCRC : public Stream{
        public:
          StreamCRC( Stream &s_Stream ) : stream( s_Stream ), CRCIN( ~0L ), CRCOUT( CRCIN ) { return; }
          
          int available( void ) { return stream.available(); }
          
          void flush( void ) { stream.flush(); }
          
          unsigned long getCRC( CRC_STREAM_ID c_ID ) { return ~( c_ID ? CRCOUT : CRCIN ); }
            
          int peek( void ) { return stream.peek(); }
            
          int read( void );
          
          void resetCRC( CRC_STREAM_ID c_ID ) { ( c_ID ? CRCOUT : CRCIN ) = ~0L; }
          
          size_t write( uint8_t u_Data );
        protected:
          Stream &stream;
          unsigned long CRCIN;
          unsigned long CRCOUT;
      };
    #endif

    Code: (StreamCRC.cpp)
     #include "StreamCRC.h"
      
      uint32_t crc_table[ 0x10 ] PROGMEM = {
        0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
        0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
      };

      void crc32Byte( unsigned long &u_CRC, uint8_t u_Data )
        {
          uint8_t u_Idx;
          u_Idx = u_CRC ^ u_Data;
          u_CRC = pgm_read_dword( crc_table + ( u_Idx & 0x0F ) ) ^ ( u_CRC >> 4 );
          u_Idx = u_CRC ^ ( u_Data >> 4 );
          u_CRC = pgm_read_dword( crc_table + ( u_Idx & 0x0F ) ) ^ ( u_CRC >> 4 );
        }  
      
      int StreamCRC::read( void )
        {
          const int i_Read = stream.read();
          if( i_Read != -1 ) crc32Byte( CRCIN, ( uint8_t ) i_Read );
          return i_Read;
        }  
        
      size_t StreamCRC::write( uint8_t u_Data )
        {
          crc32Byte( CRCOUT, u_Data );
          return stream.write( u_Data );      
        }

    Hope someone can get some use out of this, and as always any comments are appreciated.
768  Using Arduino / Networking, Protocols, and Devices / Re: WiFi shield server library corruption/crashes on: December 02, 2013, 05:52:55 am
I would like to help with a firmware solution, however I don't have a shield. So if anyone has seen a cheap(er) version available please post where you saw it.
769  Using Arduino / Networking, Protocols, and Devices / URI / Percent Encoder, useful for web server/clients. on: December 01, 2013, 11:29:44 pm
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.

Code:
#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:
Quote

Using URI_WWWFORM you will get:
Quote

And finally using URI_ALL:
Quote

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

The files are attached and provided here for people not logged in:
Code: (URIEncode.h)
#include "Arduino.h"

#ifndef HEADER_URIENCODE
  #define HEADER_URIENCODE
  
  enum URI_MODE{ URI_STANDARD, URI_WWWFORM, URI_ALL };
  
  class URIEncoder : public Print{
    public:
    
      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; }
      
    protected:
      Print &Output;
      char Mode;
  };
#endif

Code: (URIEncode.cpp)
#include "URIEncode.h"

#define URI_CHAR_COUNT  19

char URIChars[ URI_CHAR_COUNT ] PROGMEM = {
  '!', '*', '\'', '(', ')', ';', ':', '@', '&', '=', '+', '$', ',', '/', '?', '#', '[', ']', ' '
};


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;
}
  }else
b_Found = true;
  
  if( b_Found ){
  
if( u_Data == ' ' && Mode == URI_WWWFORM )
 return Output.write( '+' );

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

  }else
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.
770  Using Arduino / Networking, Protocols, and Devices / Re: Thumbs way down for Arduino WiFi shield. Read before you buy on: December 01, 2013, 07:49:39 pm
Quote
edit: I don't think you stole anybody's socket. I think the firmware overwrote your socket when your web browser requested the icon. That may be what Matt was trying to get across to me.

Yeah, not stole, but If the wrong remote socket data can be sent to my local socket, then someone could effectively receive my potentially private/secure page that I have requested.

Quote
It would be extremely helpful if I could access the remote IP and port requesting the files. If they are the same on both requests, that would explain a lot, and maybe help fix this.

You could mimic the session ID with a sequential ID, then browsers, will respond with the ID string you provide. Not useful for a first request, but subsequent requests should contain the ID.

Why not just do the mods you where talking about ( or was that the Ethernet shield only ).
771  Using Arduino / Networking, Protocols, and Devices / Re: Thumbs way down for Arduino WiFi shield. Read before you buy on: December 01, 2013, 08:18:04 am
Lucky I didn't let the browser page close, cos as you say it did load the favicon. After a short delay the tab changed its icon to that of the waterfall picture. If the wifi shield is at fault, then that is a huge blunder, no need to hack security if you can just steal someones socket.
772  Using Arduino / Networking, Protocols, and Devices / Re: Thumbs way down for Arduino WiFi shield. Read before you buy on: December 01, 2013, 08:04:13 am
Here is some useful debug info. I have received a few more corrupt images, but just received the favicon instead.
From looking at the headers, it appears it may be a bug in your code, as it sends an icon type, not just wrong data.

Quote
Request URL:http://68.99.58.119/img/waterfal.jpg
Request Method:GET
Status Code:200 OK
Request Headers
GET /img/waterfal.jpg HTTP/1.1
Host: 68.99.58.119
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.1.0.0 Safari/537.36
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
DNT: 1

Response Headers
HTTP/1.0 200 OK
Content-Type: image/x-icon
Connection: close
773  Using Arduino / Networking, Protocols, and Devices / Re: Thumbs way down for Arduino WiFi shield. Read before you buy on: December 01, 2013, 07:37:10 am
Thanks pYro_65. I think the expires, pragma, and cache-control may do it.

Different header combinations of the above set are used by different browsers/version implementations. Without the last-modified, some systems/proxies may still cache the file until they are sure there is new content, not just the possibility.

But caching doesn't seem to be the problem here, and would alleviate a lot of excess connections of a feature full website served from the Arduino.
774  Using Arduino / Networking, Protocols, and Devices / Re: Thumbs way down for Arduino WiFi shield. Read before you buy on: December 01, 2013, 07:19:29 am
Quote
So there is corruption and incorrect images in Australia and the U.K., but not in North America? Is that what I am hearing? I am wondering if there is something I can add to the header to prevent caching of the images.

This is how I do it in PHP, you can translate the headers to suit your needs.

Code:
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, max-age=0, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

If you have a time source, use the current time (GMT)  for 'Last-Modified'
775  Using Arduino / Networking, Protocols, and Devices / Re: Thumbs way down for Arduino WiFi shield. Read before you buy on: December 01, 2013, 01:25:28 am
I tried the same test, not only where the file names mismatched, but there was significant data corruption. Check out the images I have attached. I couldn't save the images directly in the browser as the cache only keeps the last downloaded version.
776  Using Arduino / Project Guidance / Re: Need Help With Redirection on: November 27, 2013, 09:15:58 pm
You should rethink any usage of goto you may consider, its best to stick to a controlled program flow over jumping around the place. And you do not really need to worry about exit(), it  is for 'end of program' states such as a failure condition that cannot be resolved.

return is used to end a function and return the execution to the caller ( where the function was originally run ).
it is required for functions that are not declared void. i.e return a value. If a void function always ends on the last line, return is not needed, however it can be used for ending the function earlier, maybe due to a switch or if condition.

break has different meanings, in a switch it is used to stop execution from entering case labels below the active case.
And inside all forms of loops it can be used to jump out of the loop, execution continues after the loop code.

You didn't mention 'continue', inside a loop it causes execution to go the continuation condition without running the rest of the loop code ( skips to next iteration ).
777  Using Arduino / Programming Questions / Re: Wrong values when accessing multidimensional array on: November 26, 2013, 12:01:13 pm
I know, that's why I switched to bytes eventually (plus that I didn't need any values bigger than 7). Before that I used (sizeof(bMap[num])/sizeof(byte) - 1) to get the size of the array.

If you want to use any size (data type) you like and not care about the nitty gritty, here is a fun little example that uses objects to gain a little more info from your arrays.

Code:
#define NUM_NUMBERS 10
#define NUM_PARTS 7

const byte bMap[NUM_NUMBERS][NUM_PARTS] = {  {0, 1, 2, 4, 5, 6}, {2, 5}, {0, 2, 3, 4, 6}, {0, 2, 3, 5, 6}, {1, 2, 3, 5}, {0, 1, 3, 5, 6}, {0, 1, 3, 4, 5, 6}, {0, 2, 5}, {0, 1, 2, 3, 4, 5, 6}, {0, 1, 2, 3, 5, 6} };

template< typename T > struct ArraySize;
template< typename T, size_t N > struct ArraySize< T[N] > { enum{ Size = N }; };
template< typename T, size_t A, size_t N > struct ArraySize< T[A][N] >{ enum{ InnerSize = A, OuterSize = N }; };

void setup() {
  Serial.begin(9600);
  Serial.print( "Size of inner index: " );
  Serial.println( ArraySize< typeof( bMap ) >::InnerSize );
  Serial.print( "Size of outer index: " );
  Serial.println( ArraySize< typeof( bMap ) >::OuterSize );
}

void loop(){}
778  Using Arduino / Programming Questions / Re: Pointer to Print Class (DualWriter) / TelnetServer [solved] on: November 26, 2013, 11:33:16 am
The ampersand (&) character has different meanings depending on where it is. There may not be much logic behind it, it just looks good I suppose. It can specify a reference, be an address-of operator, bitwise and logical 'and' operators ( T &a, &a, a & b, a && b ), the same as * can be used in maths and creating/accessing pointers ( a * b, T *a, *a ).


779  Using Arduino / Programming Questions / Re: Wrong values when accessing multidimensional array on: November 26, 2013, 09:54:13 am
Quote
Here's one thing though: I was using an array of int's before this and I got some weirder results. Because sizeof(bMap[num]) returns 14 when using int's I got double the results in my output. Somewhere in the results it started returning some other values than 0. Thos values weren't in this array, but in a different array (even a different class).

sizeof returns a count of bytes not elements. ints are 2 bytes, resulting in twice the size of the result using char/byte.

780  Using Arduino / Programming Questions / Re: (*XXX).print(); // XXX = pointer to instance that can print on: November 26, 2013, 09:18:06 am
Hi, thanks for the praise, I like helping out.

I realize now why the original code didn't work, also, the original code is the one you want to use, if you weren't doing so.
I'll explain why.

Firstly you are best to initialize the ethernet client like this:
Code:
EthernetClient ethTelnet_Client;

The reason that assigning 0 didn't work, i.e:
Code:
EthernetClient ethTelnet_Client = 0;

Is because this set the internal socket to 0, which is a valid socket number.
The default constructor sets the socket to MAX_SOCK_NUM, and this value is used in the class to decide weather to react to calls that use a real socket.

This is why using an ' anonymous temporary' object worked, i.e:
Code:
EthernetClient ethTelnet_Client = EthernetClient();

This works due to the default constructor in the anonymous temporary setting MAX_SOCK_NUM, then simply passing it on to your object.

So you can safely use the version below as well, but is implicitly done if left to do so.
Code:
EthernetClient ethTelnet_Client = MAX_SOCK_NUM;

So it was this reason my original version seemed to fail, where It was actually incorrect initialization.  smiley-razz
Pages: 1 ... 50 51 [52] 53 54 ... 142