Home AMX User Forum NetLinx Studio

Newbie Question

Hi,

I'm working at a university that uses AMX across the campus in our lecture rooms. We want to connect an occupancy sensor to the IO ports on the controller, and have the controller do a HTTP Post request to the server when occupancy is detected. I have written the following by looking through some of our other programs written by integrators and some help file trawling! however it fails to compile saying the Channel_Event line is invalid syntax.... any help greatly appreciated!


PROGRAM_NAME='OCCUPANCY'

define_device

dvIO = 5001:17:0
dvServer = 0:5:0


CHANNEL_EVENT [dvIO,2]
{

OFF: {
IP_Client_open(dvServer.PORT,'ip of server',80,IP_TCP)
SEND_STRING dvServer,"'POST /pcav/senddata.php HTTP/1.0',13,10"
SEND_STRING dvServer,"'From: bob@thebuilder.com',13,10"
SEND_STRING dvServer,"'User-Agent: HTTPTool/1.0',13,10"
SEND_STRING dvServer,"'Content-Type: application/x-www-form-urlencoded',13,10"
SEND_STRING dvServer,"'Content-Length: 32',13,10"
SEND_STRING dvServer,"13,10"
SEND_STRING dvServer,"'Someones Here!!!!!'"
}

}

Comments

  • DHawthorneDHawthorne Posts: 4,584
    You need a DEFINE_EVENT line before your channel event. Something needs to tell the compiler you are switching sections.
  • ericmedleyericmedley Posts: 4,177
    kevsach wrote: »
    Hi,

    I'm working at a university that uses AMX across the campus in our lecture rooms. We want to connect an occupancy sensor to the IO ports on the controller, and have the controller do a HTTP Post request to the server when occupancy is detected. I have written the following by looking through some of our other programs written by integrators and some help file trawling! however it fails to compile saying the Channel_Event line is invalid syntax.... any help greatly appreciated!


    PROGRAM_NAME='OCCUPANCY'

    define_device

    dvIO = 5001:17:0
    dvServer = 0:5:0


    CHANNEL_EVENT [dvIO,2]
    {

    OFF: {
    IP_Client_open(dvServer.PORT,'ip of server',80,IP_TCP)
    SEND_STRING dvServer,"'POST /pcav/senddata.php HTTP/1.0',13,10"
    SEND_STRING dvServer,"'From: bob@thebuilder.com',13,10"
    SEND_STRING dvServer,"'User-Agent: HTTPTool/1.0',13,10"
    SEND_STRING dvServer,"'Content-Type: application/x-www-form-urlencoded',13,10"
    SEND_STRING dvServer,"'Content-Length: 32',13,10"
    SEND_STRING dvServer,"13,10"
    SEND_STRING dvServer,"'Someones Here!!!!!'"
    }

    }

    not having the rig right in front of me to test.... I'd suggest trying to combine the whole set of strings into one string.

    something like:
    OFF: {
            stack_var message[300]	
    	IP_Client_open(dvServer.PORT,'ip of server',80,IP_TCP)
            message=" 'POST /pcav/senddata.php HTTP/1.0',13,10,
    	'From: [email]bob@thebuilder.com[/email]',13,10,
    	'User-Agent: HTTPTool/1.0',13,10,
    	'Content-Type: application/x-www-form-urlencoded',13,10,
    	'Content-Length: 32',13,10,
    	"13,10,
    	'Someones Here!!!!!'  "
            send_string dvServer , message
    	}
    
  • viningvining Posts: 4,368
    Not sure about the compiler problem but you shouldn't have the send strings in the channel event since you risk sending to an IP socket that hasn't yet opened. Even though you do first call the port to open it's not an immediate connection. Put the send strings in the online event handler so that when the socket is actually made (online) you then send your strings.
  • ericmedleyericmedley Posts: 4,177
    vining wrote: »
    Not sure about the compiler problem but you shouldn't have the send strings in the channel event since you risk sending to an IP socket that hasn't yet opened. Even though you do first call the port to open it's not an immediate connection. Put the send strings in the online event handler so that when the socket is actually made (online) you then send your strings.

    This is very true Vinning. To be honest, I never try to go down the road on these posts because I just don't know the whole back story. But the OP should note Vinning on this. What I'd really do is create a separate routine for handling commands that will put IP comms into a queue and then let the routine handle when to send a message.

    I think this is just good practice any time you have to leave the box for any type of input or output. I've found there's just a strange assumption that the timing of events is cut-and-dried and doesn't need to be handled. Sure, it can be a pain, but so is sussing out quirky problems with strings. It's worse when burning in systems that do IP communication. In burn-in you have a much tighter network under controlled conditions. I've always found IP networks slow down when in the actual installation. So, if I'm relying on the processor to be slow enough, I always get burned at install.

    Consequently, I just queue everything. Once you get in the habit of doing it, it come naturally and quickly.
Sign In or Register to comment.