[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 22:33:58 CET 2019


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:
- send an "ON" message to the device
- send an "OFF" message to the device
- send a "connect" message to netsend
- send an "ON" message to the device

switching the togglle to 0 will:
- send an "ON" message to the device
- send an "OFF" message to the device
- send a "connect" message to netsend
- send an "OFF" message to the device


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:
- send an "ON" message to the device
- send an "ON" message to the device
- send an "OFF" message to the device
- send a "connect" message to netsend
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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puredata.info/pipermail/pd-list/attachments/20190124/943ba94b/attachment.sig>


More information about the Pd-list mailing list