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; #X msg 184 67 connect 192.168.1.123 80; #X connect 1 0 0 0; #X connect 2 0 4 0; #X connect 2 0 5 0; #X connect 2 1 5 0; #X connect 3 0 2 0; #X connect 6 0 2 0; #X connect 7 0 2 0; #X connect 8 0 2 0;
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 [1] 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.
something like:
| [symbol on] | [GET /relay/0/?turn=$1 HTTP/1.0( | [fudiformat] | [t l l] | [list length] | [- 2] [list split] | [list append 13 10 13 10] | [list prepend send] | [list trim] | [netsend -b]
fgmadsr IOhannes
Hey Johannes,
I guess you mean [list fromsymbol] to convert symbols to their byte-representation ? ;) ++
Jack
Le 24/01/2019 à 18:07, IOhannes m zmölnig a écrit :
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 [1] 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.
something like:
| [symbol on] | [GET /relay/0/?turn=$1 HTTP/1.0( | [fudiformat] | [t l l] | [list length] | [- 2] [list split] | [list append 13 10 13 10] | [list prepend send] | [list trim] | [netsend -b]
fgmadsr IOhannes
[1] https://en.wikipedia.org/wiki/FUDI
Pd-list@lists.iem.at mailing list UNSUBSCRIBE and account-management -> https://lists.puredata.info/listinfo/pd-list
This is what I'm using I can connect and disconnect but the command syntax coming out of Pd seems to be incorrect.
#N canvas 293 155 710 697 10; #X msg 241 186 disconnect; #X floatatom 303 547 0 0 0 0 - - -; #X obj 378 555 print; #X obj 329 128 fudiformat; #X obj 329 53 symbol on; #X obj 331 180 t l l; #X obj 359 218 list length; #X obj 361 250 - 2; #X obj 327 299 list split; #X obj 327 390 list prepend send; #X obj 325 446 list trim; #X obj 325 492 netsend -b; #X obj 325 337 list append 13 10 13 10; #X obj 390 159 print; #X msg 329 89 GET /relay/0/?turn=$1 HTTP/1.0; #X msg 95 253 connect 192.168.1.123 80; #X connect 0 0 11 0; #X connect 3 0 5 0; #X connect 3 0 13 0; #X connect 4 0 14 0; #X connect 5 0 8 0; #X connect 5 1 6 0; #X connect 6 0 7 0; #X connect 8 0 12 0; #X connect 9 0 10 0; #X connect 10 0 11 0; #X connect 11 0 2 0; #X connect 11 0 1 0; #X connect 11 1 2 0; #X connect 12 0 9 0; #X connect 14 0 3 0; #X connect 15 0 11 0;
On Thu, Jan 24, 2019 at 1:38 PM Roman Haefeli reduzent@gmail.com wrote:
On Thu, 2019-01-24 at 18:24 +0100, Jack wrote:
I guess you mean [list fromsymbol] to convert symbols to their byte-representation ? ;)
Have you tried [fudiformat]?
I think IOhannes actually meant it.
Roman _______________________________________________ Pd-list@lists.iem.at mailing list UNSUBSCRIBE and account-management -> https://lists.puredata.info/listinfo/pd-list
On 1/24/19 8:20 PM, RT wrote:
This is what I'm using I can connect and disconnect but the command syntax coming out of Pd seems to be incorrect.
that patch misses the argument to [list split]. the purpose of [list split] is to remove the ";\n" at the end of the FUDI-message, so we calculate the length of the list minus 2 (for the two characters to split off). my ascii-art was a bit fuzzy there, but essentially the outlet of [- 2] was meant to go into the 2nd inlet of [list split].
gfmsard IOhannes
you can actually use [fudiformat -u] to omit the separator (; + newline), so you wouldn't need [list split]
Gesendet: Donnerstag, 24. Januar 2019 um 20:41 Uhr Von: "IOhannes m zmölnig" zmoelnig@iem.at An: pd-list@lists.iem.at Betreff: Re: [PD] Using netsend to send url / text to turn a device on and off
On 1/24/19 8:20 PM, RT wrote:
This is what I'm using I can connect and disconnect but the command syntax coming out of Pd seems to be incorrect.
that patch misses the argument to [list split]. the purpose of [list split] is to remove the ";\n" at the end of the FUDI-message, so we calculate the length of the list minus 2 (for the two characters to split off). my ascii-art was a bit fuzzy there, but essentially the outlet of [- 2] was meant to go into the 2nd inlet of [list split].
gfmsard IOhannes
Pd-list@lists.iem.at mailing list UNSUBSCRIBE and account-management -> https://lists.puredata.info/listinfo/pd-list
Thanks I made those changes. I thought I would be able to pick up Pd again after several years of not using it. CLEARLY I was wrong :-) . I'm going to go back and re-watch Rafael Hernandez Pd tutorials again https://www.youtube.com/playlist?list=PL12DC9A161D8DC5DC They where very helpful several years ago and I can definitely see that I need a refresher. Thanks to everyone for being so patient and understanding.
On Thu, Jan 24, 2019 at 5:24 PM Christof Ressi christof.ressi@gmx.at wrote:
you can actually use [fudiformat -u] to omit the separator (; + newline), so you wouldn't need [list split]
Gesendet: Donnerstag, 24. Januar 2019 um 20:41 Uhr Von: "IOhannes m zmölnig" zmoelnig@iem.at An: pd-list@lists.iem.at Betreff: Re: [PD] Using netsend to send url / text to turn a device on
and off
On 1/24/19 8:20 PM, RT wrote:
This is what I'm using I can connect and disconnect but the command
syntax
coming out of Pd seems to be incorrect.
that patch misses the argument to [list split]. the purpose of [list split] is to remove the ";\n" at the end of the FUDI-message, so we calculate the length of the list minus 2 (for the two characters to split off). my ascii-art was a bit fuzzy there, but essentially the outlet of [- 2] was meant to go into the 2nd inlet of [list split].
gfmsard IOhannes
Pd-list@lists.iem.at mailing list UNSUBSCRIBE and account-management ->
https://lists.puredata.info/listinfo/pd-list
Pd-list@lists.iem.at mailing list UNSUBSCRIBE and account-management -> https://lists.puredata.info/listinfo/pd-list
On 1/24/19 7:35 PM, Roman Haefeli wrote:
On Thu, 2019-01-24 at 18:24 +0100, Jack wrote:
I guess you mean [list fromsymbol] to convert symbols to their byte-representation ? ;)
yes, of course i meant [list fromsymbol] instead of the non-existing [list totext], for converting symbols to bytelists ( iwas confused by [text tolist])
Have you tried [fudiformat]?
I think IOhannes actually meant it.
yes, that is what i recommended for converting entire messages to bytelists.
fgmards IOhannes
On Thu, Jan 24, 2019 at 11:36 AM RT ratulloch@gmail.com 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
If you don't have to use vanilla Pd it's easier to use [httpreq] and
[tcpclient].
Martin
Thanks all this really helps, my toggle / select is a little messy but it turns my Shelly1 device on and off from PureData.
Thanks
#N canvas 300 179 710 697 10; #X msg 241 261 disconnect; #X floatatom 303 622 0 0 0 0 - - -; #X obj 329 203 fudiformat; #X obj 331 255 t l l; #X obj 359 293 list length; #X obj 361 325 - 2; #X obj 327 360 list split; #X obj 327 465 list prepend send; #X obj 325 521 list trim; #X obj 325 567 netsend -b; #X obj 325 412 list append 13 10 13 10; #X obj 390 234 print; #X msg 95 330 connect 192.168.1.20 80; #X obj 525 398 print; #X obj 432 206 print; #X msg 343 159 GET /relay/0/?turn=$1 HTTP/1.0; #X obj 441 24 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 1; #X obj 347 100 symbol on; #X obj 424 101 symbol off; #X obj 433 60 select 1 0; #X obj 379 34 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 -1; #X connect 0 0 9 0; #X connect 2 0 3 0; #X connect 2 0 11 0; #X connect 3 0 6 0; #X connect 3 1 4 0; #X connect 4 0 5 0; #X connect 5 0 6 1; #X connect 6 0 10 0; #X connect 6 0 13 0; #X connect 7 0 8 0; #X connect 8 0 9 0; #X connect 9 0 1 0; #X connect 10 0 7 0; #X connect 12 0 9 0; #X connect 15 0 2 0; #X connect 15 0 14 0; #X connect 16 0 20 0; #X connect 16 0 19 0; #X connect 17 0 15 0; #X connect 18 0 15 0; #X connect 19 0 17 0; #X connect 19 1 18 0; #X connect 20 0 17 0; #X connect 20 0 18 0; #X connect 20 0 12 0;
On Thu, Jan 24, 2019 at 3:11 PM Martin Peach chakekatzil@gmail.com wrote:
On Thu, Jan 24, 2019 at 11:36 AM RT ratulloch@gmail.com 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
If you don't have to use vanilla Pd it's easier to use [httpreq] and
[tcpclient].
Martin
On 1/24/19 10:14 PM, RT wrote:
Thanks all this really helps, my toggle / select is a little messy
please don't!
switching the toggle to 1 will:
switching the togglle to 0 will:
and this just accidentally happens to be like that. if you re-paint your patch from an image, it might as well do the following when switching the toggle to 1:
which clearly is just nonsense.
so why are you sending those odd "ON" and "OFF" messages and the beginning? you will also get ugly "already connected" errors, if you switch the device fast enough, so that the webserver has not terminated the connection yet.
the *first* rule you should learn when starting to patch in Pd, is using trigger, whenever you want to connect a single outlet to more than one inlets. everytime. always. every single time. really.
so remove the entire hickhack with your toggle and bang, and replace it by a simple:
[tgl] | [select 1 ] | | [on( [off( | ________/ |/ [symbol] |
then, between [list strip] and [netsend] do the following:
| [list strip] | [t a b] | | | [disconnect, connect 192.168.1.20 80( | ____/ |/ [netsend -b]
this will start a new connection exactly before you are going to send data to the webserver. and it will only send the HTTP-request once (with the correct parameters)
gfnadsr IOhannes
i use 2 options:
A) for osx and linux with ggee's shell
[curl -s http://192.168.1.123/relay/0/?turn=on( | [ggee/shell]
B) for win/lin/osx i prefer
[http://192.168.1.123/relay/0/?turn=on( | [mrpeach/httpreq] | | [connect 192.168.1.123 80( | / [mrpeach/tcpclient]
liebe grüße marco
Am 24.01.19 um 21:11 schrieb Martin Peach:
On Thu, Jan 24, 2019 at 11:36 AM RT <ratulloch@gmail.com mailto:ratulloch@gmail.com> 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
If you don't have to use vanilla Pd it's easier to use [httpreq] and [tcpclient].
Martin
Pd-list@lists.iem.at mailing list UNSUBSCRIBE and account-management -> https://lists.puredata.info/listinfo/pd-list