Pages: [1]   Go Down
Author Topic: Arduino Internet Access V1.  (Read 418 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Edison Member
*
Karma: 20
Posts: 2115
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void TestConnect()
{
  SetupRemotePort("80");  //change for your needs
  SetupRemoteHost("myarduino.info"); //change for your needs
  RemoteConnect();  //establish connection
  //RemoteCRLFSendPacket("GET /Whatever");  //removed
}


basically this is where the magic happens, it seems to work fine /sending/ packets but when you send data back to the arduino
it buffers, eg if you send

'123'
delay(1000);
'456'

you'll see this happen... 123 delay...  456

if you send
'123'
'456'


the result will be 123456 (not separate data strings) because it stacks on the data at the end, in TCP IP i think they call this chunking
on my client, i can get around that by looking for $$ and && and removing a bit at time getting the right
data i need.

same needs to be done via the C++ source but i'm  not that good smiley-razz

So


  SetupRemotePort("80");  //change for your needs
  SetupRemoteHost("myarduino.info"); //change for your needs
  RemoteConnect();  //establish connection
  //RemoteCRLFSendPacket("GET /Whatever");  //removed


first instructs the client to setup a remote port for 80
then the server myarduino.info
then the packet to make a connnection

then the actual command, you could change it to post data to your own server and send sensor info


i totally agree, the client side is not yet finished, but it's working, i need to add support for disconnection
and other stuff, but until i sort out the buffering issue over serial on arduino side, it's kinda pointless and
i may need to add more complex protocol to deal with the packet chunking..

the delay(5000) in the loop, well that's there because i wanted to give it enough time to recv the data
but problem is TOO much data and the data well goes missing because the client is sending more data
than the code can handle, so remove the delay, fix the way it reads the data?.. and check for buffering.

if you're not too fussed about getting data from a server, it works quite well, or you'll need to modify it
and show the rest of us smiley

Quote
How to use.

1. run ArduinoClient.exe
2. hit the button "Establish Connection" change the com port box from 4 to your port before pressing the button
3. done

(the 2 send buttons, it simply sends data down the com port to your arduino board) i used it to trigger off a test connection, you can modify it to happen on a button press or an event etc. 1st  "waskeup" you'll
see arduino side that simply instructs the client on windows to make a connection to a specified port/server the other Send button sends the specified string to the remote server.

All source code attached, any questions or modifications i need to make, just let me know and i'll recompile and upload. increasing the version by .1 eg v1.1, v1.2 , v1.3 so no mistakes are made.

Other than that, i got it connecting to my own little server and i was able to recv/send data providing the delay(5000) is removed and you buffer the data properly, not done... (god knows how either right now)

* Arduino Internet AccessV1.zip (195.05 KB - downloaded 7 times.)
Logged

Offline Offline
Edison Member
*
Karma: 20
Posts: 2115
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
procedure TForm1.Timer1Timer(Sender: TObject);
Var
 T2,S: String;
 Payload: String;
 echars: String;
begin
{If Debug=True Then
  Begin
  s:=ReadText;
  if s<>'' Then
   Begin
    form1.memo1.lines.add(s);
    Exit;
   End;
  End;}
{ if pos('Debug:',s)>0 then
  Begin
    Delete(S,1,6);
    T2:=Copy(s,1,pos('/',s)-1);
    form1.memo1.lines.add(t2);
    Exit;
  End;}
 If ConnX=True Then
  Begin
   If Tmp<>'' Then
    Begin
     S:=Tmp+ReadText;
     tmp:='';
    End
      else
    S:=ReadText;
    if ScanIt('&&',S)>1 Then
      Begin
        T2:=S;
        T2:=Copy(T2,1,Pos('&&',T2)+1);
        Delete(s,1,Length(T2));
        Tmp:=Tmp+s;
        S:=T2;
      End;
      Echars:=Copy(S,Length(S)-1,2);
      if (Echars<>'&&') and (S<>'') Then
        Begin
         tmp:=tmp+S;
         S:='';
        End;
    If S<>'' Then
       Begin
//         Memo1.lines.add(s);
          Begin
           Payload:=S;
           If Pos('&&',PayLoad)>0 Then
              PayLoad:=Copy(Payload,1,Length(Payload)-2);
           Delete(PayLoad,1,3);
           if Copy(S,1,2)='$$' Then
             Begin
                 Memo1.lines.add(PayLoad);
                //$$1 = Host
                //$$2 = Port
                //$$3 = Connect
                //$$4 = Disconnect
                //$$5 = Payload For Remote Client
                //$$6 = Test Packet
                Case S[3] Of
                  '1': RemoteHost:=Payload;
                  '2': RemotePort:=StrToInt(PayLoad);
                  '3':
                     Begin
                       Form1.ClientSocket1.Host:=RemoteHost;
                       Form1.ClientSocket1.Port:=RemotePort;
                       Form1.ClientSocket1.Active:=True;
                       Form1.Memo1.Lines.add('Establishing Connection To: '+RemoteHost+' Port: '+IntToStr(RemotePort));
                     //  Debug:=True;
                     End;
                  '4': Form1.ClientSocket1.Active:=False;
                  '5': Form1.ClientSocket1.Socket.SendText(PayLoad);
             End;

           End;
        End;
    //    if Form1.ClientSocket1.active=True Then
       //   ClientSocket1.Socket.SendText(S); //send it to the server from arduino
    End;
  End;
end;

Client side, this is how I dealt with the packet chunking (buffering issue) and that's to simply get what's known to be a full packet length up to &&
and any data left over gets put into a global temp buffer, and on the next read, the new data is appended onto the old tmp packet..

I just about got my head around this in Pascal, fat chance i'd be able to code something similar in C++ - i'm hoping someone else can so i can
make the changes client side to speed / optimize it.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 241
Posts: 24480
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is this some kind of blog, or do you have a question?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Edison Member
*
Karma: 20
Posts: 2115
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

no, this is for anyone who wants to give their regular arduino board (no ethernet shield) internet access via the usb cable... not sure where this goes because it's not yet fully complete but it does work as intended as of now...  so i'm not sure where this thread should go because it crosses so many areas of this board, programming needs to be done on the C++ file, mods need to be done to the client based on what gets done to the ino file...

Logged

Pages: [1]   Go Up
Jump to: