Go Down

Topic: Help intergrating some code i found (Ethernet Code).... (Read 2528 times) previous topic - next topic

Marek080

@zoomkat: you forgot to show us the interesting patched part - this sketch obviously only gives an
Code: [Select]
error: 'class EthernetClient' has no member named 'getRemoteIP'
loved the 68000 assembler back then and now I have to deal with THIS 8 bit thingy

cjdelphi

Nice one but im still staggering around in near darkness may i see the rest of the code then? lol

Marek080

loved the 68000 assembler back then and now I have to deal with THIS 8 bit thingy

cjdelphi

oops, I used Android (and you don't see scroll bars on the code) so it looked like far less code than you posted...

I'll try it out, thanks....

Marek080

It is only three lines to add to the code to get the remote IP and you already figured out the most important one. The rest is the explanation.
loved the 68000 assembler back then and now I have to deal with THIS 8 bit thingy

cjdelphi

OK I added the lines, but it's still going over my head..

in short the code I just uploaded returns these errors :(

Quote









In file included from WebServer.cpp:7:
C:\arduino\arduino-1.0\libraries\Ethernet/utility/w5100.h:234: error: 'static uint16_t W5100Class::writeRIPR(uint8_t*)' cannot be overloaded
C:\arduino\arduino-1.0\libraries\Ethernet/utility/w5100.h:232: error: with 'static uint16_t W5100Class::writeRIPR(uint8_t*)'
C:\arduino\arduino-1.0\libraries\Ethernet/utility/w5100.h:234: error: 'static uint16_t W5100Class::readRIPR(uint8_t*)' cannot be overloaded
C:\arduino\arduino-1.0\libraries\Ethernet/utility/w5100.h:232: error: with 'static uint16_t W5100Class::readRIPR(uint8_t*)'




(EthernetCode ...zip contains my modified ethernet lib including the sub folders and modifications)


Thanks for helping.....

Marek080

#21
Apr 08, 2012, 03:00 am Last Edit: Apr 08, 2012, 03:04 am by Marek080 Reason: 1
I propose to delete the additional copy of ethernet lib and add the line
Code: [Select]
__GP_REGISTER_N(RIPR,   0x000C, 4); // Remote IP address
directly to w5100.h in the Arduino library directory. It is a small change without the hassle of cloning the library. You just have to remember that you made the change when updating to a newer version of Arduino.

The rest is done in your sketch by including w5100.h and calling the new function
Code: [Select]
#include <Ethernet.h>
#include <utility/w5100.h>
...
uint8_t remoteIP[4];
...
W5100.readRIPR(remoteIP);
loved the 68000 assembler back then and now I have to deal with THIS 8 bit thingy

cjdelphi

Step 1 . Open w5100.h add the line

 __GP_REGISTER_N(RIPR,   0x000C, 4); // Remote IP address


Step 2.  

Insert code


 static uint16_t writeRIPR(uint8_t *_buff) {
   return write(0x000C, _buff, 4);
 }
 static uint16_t readRIPR(uint8_t *_buff) {
   return read(0x000C, _buff, 4);
 }
 static uint16_t writeSIPR(uint8_t *_buff) {
   return write(0x000F, _buff, 4);
 }
 static uint16_t readSIPR(uint8_t *_buff) {
   return read(0x000F, _buff, 4);
 }

/// What file?


Step 3, compile?

cjdelphi

how does coding in C/C++ not make someone drink excessively ?

Marek080

#24
Apr 08, 2012, 03:08 am Last Edit: Apr 08, 2012, 03:10 am by Marek080 Reason: 1
No, wrong. There is only one step. Only one line to add to w5100.h - do not drink and program :P

I edited my previous post, so read it again, please.
loved the 68000 assembler back then and now I have to deal with THIS 8 bit thingy

zoomkat


@zoomkat: you forgot to show us the interesting patched part - this sketch obviously only gives an
Code: [Select]
error: 'class EthernetClient' has no member named 'getRemoteIP'


Just now remembering, below has the info on how to make the code work to get the client IP address. Just a little copy/paste work in the correct files.

http://arduino.cc/forum/index.php/topic,82416.msg619420.html#msg619420
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

cjdelphi

#26
Apr 08, 2012, 04:24 am Last Edit: Apr 08, 2012, 04:28 am by cjdelphi Reason: 1
Yayyyyyyyy thank you!!!

for future reference for anyone else..

Code: [Select]

       char crrip[16];
       byte rip[4];
 
       client.getRemoteIP(rip); // where rip is defined as byte rip[] = {0,0,0,0 };     
       sprintf(crrip, "%d.%d.%d.%d", (unsigned char)rip[0], (unsigned char)rip[1], (unsigned char)rip[2], (unsigned char)rip[3]);
       client.print("Welcome ");
       client.println(crrip);


modifications to ethernet...

Quote

I added the following lines to the end of the EthernetClient.cpp file:
uint8_t *EthernetClient::getRemoteIP(uint8_t remoteIP[])
{
 W5100.readSnDIPR(_sock, remoteIP);
 return remoteIP;
}

I then added the following line (under the virtual void stop(); line)to the EthernetClient.h file:
uint8_t *getRemoteIP(uint8_t RemoteIP[]);//adds remote ip address

Finally I used the following code in my sketch to access the remote IP:
client.getRemoteIP(rip); // where rip is defined as byte rip[] = {0,0,0,0 };

to display the IP in the serial monitor, I used:

for (int bcount= 0; bcount < 4; bcount++)
    {
       Serial.print(rip[bcount], DEC);
       if (bcount<3) Serial.print(".");
    }

I'm not sure that this is the most elegant way, but it works in the IDE v1.0


Works perfectly Cheers man :)


http://110.175.97.110:1234


There it is in action :) - that means I can now play with some of the other functionality  like remote port etc etc (actually one day...maybe lol)





[/quote]

Go Up