Arduino Internet Access V1.
code: [select]
void testconnect()
{
setupremoteport("80"); //change needs
setupremotehost("myarduino.info"); //change needs
remoteconnect(); //establish connection
//remotecrlfsendpacket("get /whatever"); //removed
}
basically magic happens, seems work fine /sending/ packets when send data arduino
it buffers, eg if send
'123'
delay(1000);
'456'
you'll see happen... 123 delay... 456
if send
'123'
'456'
the result 123456 (not separate data strings) because stacks on data @ end, in tcp ip think call chunking
on client, can around looking $$ , && , removing bit @ time getting right
data need.
same needs done via c++ source i'm not

so
setupremoteport("80"); //change needs
setupremotehost("myarduino.info"); //change needs
remoteconnect(); //establish connection
//remotecrlfsendpacket("get /whatever"); //removed
first instructs client setup remote port 80
then server myarduino.info
then packet make connnection
then actual command, change post data own server , send sensor info
i totally agree, client side not yet finished, it's working, need add support disconnection
and other stuff, until sort out buffering issue on serial on arduino side, it's kinda pointless ,
i may need add more complex protocol deal packet chunking..
the delay(5000) in loop, that's there because wanted give enough time recv data
but problem data , data goes missing because client sending more data
than code can handle, remove delay, fix way reads data?.. , check buffering.
if you're not fussed getting data server, works quite well, or you'll need modify it
and show rest of

quote
how use.
1. run arduinoclient.exe
2. hit button "establish connection" change com port box 4 port before pressing button
3. done
(the 2 send buttons, sends data down com port arduino board) used trigger off test connection, can modify happen on button press or event etc. 1st "waskeup" you'll
see arduino side instructs client on windows make connection specified port/server other send button sends specified string remote server.
all source code attached, questions or modifications need make, let me know , i'll recompile , upload. increasing version .1 eg v1.1, v1.2 , v1.3 no mistakes made.
other that, got connecting own little server , able recv/send data providing delay(5000) removed , buffer data properly, not done... (god knows how either right now)
code: [select]
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<>'&&') , (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 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 server arduino
end;
end;
end;
client side, how dealt packet chunking (buffering issue) , that's what's known full packet length &&
and data left on gets put global temp buffer, , on next read, new data appended onto old tmp packet..
i got head around in pascal, fat chance i'd able code similar in c++ - i'm hoping else can can
make changes client side speed / optimize it.
Arduino Forum > Using Arduino > Project Guidance > Arduino Internet Access V1.
arduino
Comments
Post a Comment