PUT or POST format to reply on a GET sended from App Inventor 2

415 views
Skip to first unread message

tootai

unread,
Jun 23, 2015, 12:12:12 PM6/23/15
to mitappinv...@googlegroups.com
Hi,

I'm programming an application to setup radio 433Mhz devices through Raspberry/Arduino. As there is no TCP library to use with Inventor, I send commands using web1. I got it work from Android application to PI, a selfmade php script using socket and running on the PI being the master piece of the design (no web server involved).

Now I would like to send datas (in my case 10 digits) from php script to the application. For this I use the sample from tutorial Stock Market App but it doesn't work. My apps blocks are showed in the Selection_077 file. One thing: I just send the get, no URL being defined (but also tried with) as it is defined in the web component, not on port 80, lets say port 12345.

I effectively receive the GET from the app in the script:

___TCP/IP Connection___
NEW SEQUENCE
--- BEGIN RECEIVE ---
GET / HTTP/1.1
User-Agent: Dalvik/2.1.0 (Linux; U; Android 5.1.1; Nexus 5 Build/LMY48B)
Host: <myHostName>:12345
Connection: Keep-Alive
Accept-Encoding: gzip
--- END ---
and reply with (php code):

$data = "HTTP/1.1 200 OK\nPUT / HTTP/1.1\nContent-Length: 10\nContent-Type: text/plain\n\n1000000000\r\n";
$buf=socket_write($msgsock, $data, strlen($data)) or die("Cannot write to socket\n");
socket_close($msgsock);

Above cmd output being
--- BEGIN REPLY ---
HTTP/1.1 200 OK
PUT / HTTP/1.1
Content-Length: 10
Content-Type: text/plain

1000000000
--- END ---

I tried also to send without the PUT / HTTP/1.1 header, no more luck.

If someone could help me on this, would be great :-)

Thanks in advance,

Daniel
Sélection_077.png

Taifun

unread,
Jun 23, 2015, 12:23:56 PM6/23/15
to mitappinv...@googlegroups.com
see this thread https://groups.google.com/d/msg/mitappinventortest/2rQNmKMYkRE/tps-Lz_s52oJ and try the url in format http://xxx.xxx.xxx.xxx:xxxx (ip:port)
Taifun

Trying to push the limits of App Inventor! Snippets and Tutorials from Pura Vida Apps by Taifun.         

tootai

unread,
Jun 23, 2015, 1:05:53 PM6/23/15
to mitappinv...@googlegroups.com
Hi Taifun,

thanks for the link but as I said in my original message, I can receive datas (the PUT header from app) without any problem. It's the other way were I face the problem, eg php script => app.

Regards

Daniel

Taifun

unread,
Jun 23, 2015, 1:18:06 PM6/23/15
to mitappinv...@googlegroups.com
ok, so the GET works
you might want to explain what does not work and which blocks did you use for that?
Taifun

Taifun

unread,
Jun 23, 2015, 1:58:39 PM6/23/15
to mitappinv...@googlegroups.com
let's assume, you are trying to PUT the following to the server

PUT / HTTP/1.1
Content-Length: 10
Content-Type: text/plain
1000000000

just use these blocks



hope that helps
Taifun

tootai

unread,
Jun 23, 2015, 4:32:55 PM6/23/15
to mitappinv...@googlegroups.com
Taifun, I got it. Problem was in appinventor, web1.saveresponse was activated ! In this case Text goes anywhere I guess.
 
Everything is fine now, many thanks for your help.

Regards

Daniel
Reply all
Reply to author
Forward
0 new messages