[PD] Using netsend to send url / text to turn a device on and off
IOhannes m zmölnig
zmoelnig at iem.at
Thu Jan 24 18:07:37 CET 2019
On 1/24/19 5:33 PM, RT wrote:
> I'm trying to turn on and off a device using Pd by sending a URL. At the
> moment to turn the device on I just type in a url in the browser and to
> turn it off I type in another one url .
> To turn the device on I send http://192.168.1.123/relay/0/?turn=on
> To turn the device off I send http://192.168.1.123/relay/0/?turn=off
> I can connect to the device using *connect* and *netsend* but I couldn't
> find an example / correct syntax / format on how to send the required url
> out of Pd.
> This is what I'm using below
> #N canvas 162 516 623 513 10;
> #X msg 535 750 \; pd dsp 1;
> #X obj 536 724 loadbang;
> #X obj 248 207 netsend;
> #X msg 272 110 disconnect;
> #X floatatom 218 272 0 0 0 0 - - -;
> #X obj 280 275 print;
> #X msg 403 171 send /relay/0/?turn=off;
> #X msg 404 136 send /relay/0/?turn=on;
that won't work.
when using [send ...(, Pd will use FUDI  at the application layer.
but you want to communicate with a webserver, so you need to use HTTP as
the application layer protocol.
the *actual* string (in HTTP) you want to send is something like:
GET /relay/0/?turn=off HTTP/1.0
you can use [netsend] to send raw bytes (using the "-b" mode).
you also can use [list totext] to convert symbols to their
byte-representation (translating the characters to ASCII).
since [list totext] only takes single symbols (and not entire messages),
an even easier way would be to use [fudiformat], which will convert a
message into it's FUDI representation (with trailing semicolon, and
everything). just strip of the unwanted characters (the trailing
semicolon), and append proper CRLF terminators and you should be done.
[GET /relay/0/?turn=$1 HTTP/1.0(
[t l l]
| [list length]
| [- 2]
[list append 13 10 13 10]
[list prepend send]
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 833 bytes
Desc: OpenPGP digital signature
More information about the Pd-list