General call into local network

alexander77alexander77 Junior MemberPosts: 17
In a system with 6 controllers at the beginning one controller is attatched to a gateway for Building Enviroment. For safety reasons this attachment must be flexible; which means, if the controller fails another one has to take control.
This part works so far.
The other thing is: the other controllers need to know who actually is in control of the gateway. Therefore I am looking for a way to place a call 'into the network' in the form send_string dvxxx, 'who controlls the gateway' and expecting an answer like '192.168.0.xxx is on duty'.
Is there a way to place a 'general call' without knowing an ip-address?

Alexander

Comments

  • jimmywjimmyw Junior Member Posts: 112
    There sure is!
    IP_MC_SERVER_OPEN (PORT1,'239.255.255.250',UDP_PORT_NUMBER)
  • alexander77alexander77 Junior Member Posts: 17
    Thx,
    I tried it with the example in the help file.
    The ip-address and the port used there are the ones used for the Simple Service Discovery Protocol (SSDP).
    I tried to start a server on one machine and a client on the other machine. The client is transmitting a short text package every 5 seconds. Sorry, the server does not receiving anything. With the ip-address and port 1900 many devices send their identification, but thats not what I want. Using different ip's and/or ports leave the input buffer of the server empty.

    Has anyone a working example for that kind of communication?
  • jimmywjimmyw Junior Member Posts: 112
    Has anyone a working example for that kind of communication?

    I can make one, but its as simple as this

    on each system:
    define_device
    ndvTester = 0:11:0
    
    
    DEFINE_START
    wait 100 IP_MC_SERVER_OPEN(ndvTester.port,'239.255.255.250',1900)
    
    DEFINE_EVENT
    DATA_EVENT[ndvTester]{
        ONLINE:{
    	send_string 0, "'ndvTester online'"
    	send_string 0, "'ONLINE[',itoa(GET_SYSTEM_NUMBER()),']',13,10"
    	
        }
        OFFLINE:{
    	//its a MC, it will never go offline unless you tell it to
    	send_string 0, "'ndvTester offline'"
    	
        }
        ONERROR:{
    	send_string 0, "'ndvTester error'"
        }
        STRING:{
    	LOCAL_VAR CHAR theString[1000]
    	LOCAL_VAR CHAR theIP[20]
    	theIP = data.sourceip
    	theString = data.text
    	send_string 0, "'ndvTester string[',theIP,']'"
    	
    	SWITCH(theIP){
    	    CASE '192.168.1.61':
    	    CASE '192.168.1.62':
    	    CASE '192.168.1.63':
    	    CASE '192.168.1.64':
    	    CASE '192.168.1.65':
    	    CASE '192.168.1.66':{
    		//do stuff
    	    }
    	    CASE '192.168.1.100':{
    		//ignore this one
    	    }
    	    DEFAULT:{
    	    	while( find_string(theString,"10",1) ){
    		    send_string 0, "remove_string(theString,"10",1)"
    		}
    		send_string 0, "'----------------'"
    	    }
    	}
        }
        COMMAND:{
    	
        }
    }
    
  • alexander77alexander77 Junior Member Posts: 17
    Thx, jimmyw,

    the server-side works; as I have posted before, I receive a lot of messages from other devices in my network, with your solution and also with mine, but not from my second AMX-controller.
    So my question is: how is the construction on the client-side?
  • jimmywjimmyw Junior Member Posts: 112
    ok, I entered this in netlinx and wrote the other side as well, this SHOULD work, but I havent had a chance to do everything else and upload it to a master, I am on lunch break
    DEFINE_DEVICE
        ndvMC_Server	= 0:15:0
        ndvMC_Client	= 0:16:0
    
    DEFINE_VARIABLE
        VOLATILE char bInControl = False
    
    
    DEFINE_START
    wait 90 IP_CLIENT_OPEN (ndvMC_Client.Port,'239.255.255.250',1900,IP_UDP)
    wait 100 IP_MC_SERVER_OPEN(ndvMC_Server.port,'239.255.255.250',1900)
    
    DEFINE_EVENT
    
    DATA_EVENT[ndvMC_Server]{
        ONLINE:{
    	send_string 0, "'ndvMC_Server online'"
    	send_string ndvMC_Client, "'ONLINE[',itoa(GET_SYSTEM_NUMBER()),']'"
    	
        }
        OFFLINE:{
    	//its a MC, it will never go offline unless you tell it to
    	send_string 0, "'ndvMC_Server offline'"
    	
        }
        ONERROR:{
    	send_string 0, "'ndvMC_Server error'"
        }
        STRING:{
    	LOCAL_VAR CHAR theString[1000]
    	LOCAL_VAR CHAR theIP[20]
    	LOCAL_VAR CHAR theCommand[20]
    	LOCAL_VAR INTEGER theMasterNumber
    	theIP = data.sourceip
    	theString = data.text
    	send_string 0, "'ndvMC_Server string[',theIP,']'"
    	
    	SWITCH(theIP){
    	    CASE '192.168.1.61':
    	    CASE '192.168.1.62':
    	    CASE '192.168.1.63':
    	    CASE '192.168.1.64':
    	    CASE '192.168.1.65':
    	    CASE '192.168.1.66':{//lets assume these are our masters
    		theMasterNumber = GET_SYSTEM_NUMBER()
    		theCommand = REMOVE_STRING(theString,'[',1)
    		SWITCH(theCommand){
    		    CASE 'INCONTROL[':{
    			//this lets all masters know who is in charge
    			//I would do a check to see if 1 isnt seen in X
    			//number of broadcasts to assume its offline
    			//and then ask master 2 to take over, etc,etc
    		    }
    		    CASE 'TAKECONTROL[':{
    			//parse, see if the broadcast master number == ours, then set bInControl = true
    			//and do more stuff?
    		    }
    		    
    		}
    	    }
    	    CASE '192.168.1.100':{
    		//ignore this one
    		//add other noisy devices to this, or simply comment out the "DEFAULT"
    	    }
    	    DEFAULT:{
    	    	while( find_string(theString,"10",1) ){
    		    send_string 0, "remove_string(theString,"10",1)"
    		}
    		send_string 0, "'----------------'"
    	    }
    	}
        }
        COMMAND:{
    	
        }
    }
    
    DEFINE_PROGRAM
    wait 50 'IP_MC_BROADCAST'{
        send_string ndvMC_Client, "'INCONTROL[',itoa(GET_SYSTEM_NUMBER()),']',itoa(TYPE_CAST(bInControl))"
    }
    
    
  • alexander77alexander77 Junior Member Posts: 17
    I did some small modifications for better readability of the output.

    And I added the following:
    DATA_EVENT[ndvMC_Client]{
    onerror: {
    local_var long ierr
    ierr = data.number
    send_string 0, "'_____________ error: ',itoa(ierr),13,10"
    }
    }

    Welcome to NetLinx v3.60.453 Copyright AMX LLC 2010
    >msg on all
    All Extended diagnostic information messages turned on.
    >(0000012525) Memory Available = 37414696 <230024>
    (0000012808) DeviceManager 0.0.1 has been started
    (0000013525) Memory Available = 37346512 <68184>
    (0000014709) DeviceAccess 0.0.1 has been started
    (0000014758) CCypherConnection task spawned Successfully, task Id: 1C73790
    (0000014758) I2C priority: 99
    (0000014758) I2C stack: 10000
    (0000014759) OK to spawn I2CRx Task
    (0000014759) TaskI2CRx start
    (0000014818) It's a 4100
    (0000014908) CI2CProcess::request400K_I2C hcs12: 0
    (0000015008) CI2CProcess::request400K_I2C hcs12: 1
    (0000015108) CI2CProcess::request400K_I2C hcs12: 2
    (0000015208) CI2CProcess::request400K_I2C hcs12: 3
    (0000015208) CI2CProcess::processI2C400K hcs12 m_I2C400KAck: 1
    (0000015209) CI2CProcess::processI2C400K hcs12 m_I2C400KAck: 3
    (0000015209) CI2CProcess::processI2C400K hcs12 m_I2C400KAck: 6
    (0000015210) CI2CProcess::processI2C400K hcs12 m_I2C400KAck: a
    (0000015210) CI2CProcess::processI2C400K pro all four have ACK-ed, changed I2C t
    o 400K
    (0000015525) Memory Available = 37130008 <216504>
    (0000015541) Memory Available = 37072408 <57600>
    (0000016108) DynamicDeviceDetector 0.0.1 has been started
    (0000016307) CI2CProcess::querySequenceSupport hcs12: 0
    (0000016408) CI2CProcess::querySequenceSupport hcs12: 1
    (0000016507) CI2CProcess::querySequenceSupport hcs12: 2
    (0000016524) Memory Available = 36904056 <168352>
    (0000016608) CI2CProcess::querySequenceSupport hcs12: 3
    (0000016608) CI2CProcess::processQuerySequenceAck Sequence supported
    (0000016608) CICSPManager::start
    (0000016609) It's a 4100
    (0000016609) CICSPManager::send device info download: dev: 5001, what's state: 4
    (0000016609) CICSPTxProcess::sendPortCount device No: 5001, system No: 1
    (0000016624) Memory Available = 36867536 <36520>
    (0000016741) Memory Available = 36857360 <10176>
    (0000016857) Memory Available = 36847344 <10016>
    (0000016874) Memory Available = 36836048 <11296>
    (0000016892) Send Initialization Messages to the HCS12s
    (0000017758) IPConnectionMgr is running
    (0000018524) Memory Available = 36612880 <223168>
    (0000019524) Memory Available = 36561776 <51104>
    (0000019755) 23:20:44.433 EVENT Started ServletHttpContext[/]
    (0000019946) 23:20:45.183 EVENT Started ServletHttpContext[/]
    (0000020450) 23:20:45.683 EVENT Started ServletHttpContext[/]
    (0000020454) RootServlet 0.0.1 has been started
    (0000020523) Memory Available = 36453784 <107992>
    (0000020917) 23:20:46.149 EVENT Started ServletHttpContext[/]
    (0000020921) DeviceServlet 0.0.1 has been started
    (0000021523) Memory Available = 36062968 <390816>
    (0000021568) 23:20:46.799 EVENT Started ServletHttpContext[/]
    (0000021572) ConfigServlet 0.0.1 has been started
    (0000022150) 23:20:47.383 EVENT Started ServletHttpContext[/]
    (0000022154) DVXSPConfigServlet 0.0.1 has been started
    (0000022523) Memory Available = 35957112 <105856>
    (0000022834) 23:20:48.066 EVENT Started ServletHttpContext[/]
    (0000022838) SecurityServlet 0.0.1 has been started
    (0000023333) 23:20:48.566 EVENT Started ServletHttpContext[/]
    (0000023337) DynamicServlet 0.0.1 has been started
    (0000023383) 23:20:48.616 EVENT Starting Jetty/4.2.x
    (0000023610) 23:20:48.849 EVENT Started SocketListener on 0.0.0.0:80
    (0000024409) 23:20:49.649 EVENT Started SocketListener on 0.0.0.0:443
    (0000024412) 23:20:49.649 EVENT Started [email protected]
    (0000024522) Memory Available = 35467528 <489584>
    (0000024582) CIpInterpreter::Run - Execute Startup Code
    (0000025073) CIpEvent::OnLine 0:1:1
    (0000025073) CIpEvent::OnLine 5001:1:1
    (0000025074) CIpEvent::OnLine 5001:2:1
    (0000025074) CIpEvent::OnLine 5001:3:1
    (0000025075) CIpEvent::OnLine 5001:4:1
    (0000025075) CIpEvent::OnLine 5001:5:1
    (0000025076) CIpEvent::OnLine 5001:6:1
    (0000025076) CIpEvent::OnLine 5001:7:1
    (0000025076) CIpEvent::OnLine 5001:8:1
    (0000025077) CIpEvent::OnLine 5001:9:1
    (0000025077) CIpEvent::OnLine 5001:10:1
    (0000025078) CIpEvent::OnLine 5001:11:1
    (0000025078) CIpEvent::OnLine 5001:12:1
    (0000025079) CIpEvent::OnLine 5001:13:1
    (0000025081) CIpEvent::OnLine 5001:14:1
    (0000025085) CIpEvent::OnLine 5001:15:1
    (0000025089) CIpEvent::OnLine 5001:16:1
    (0000025093) CIpEvent::OnLine 5001:17:1
    (0000028201) IPDeviceDetector.run(): failed to join multicast group
    (0000028521) Memory Available = 35454048 <13480>
    (0000028971) Error sending UDP packet (IP=EFFFFAFB) (Error=65)
    (0000034071) CIpEvent::OnLine 0:16:1
    (0000034520) Memory Available = 35443376 <10672>
    (0000035071) SendString to socket-unknown sendto error 0x0
    (0000035072) CIpEvent::OnLine 0:15:1
    (0000035072) ndvMC_Server online
    (0000035072) SendString to socket-unknown sendto error 0x0
    (0000035073) CIpEvent::OnError 0:16:1
    (0000035074) _____________ error: 13

    (0000035074) CIpEvent::OnError 0:16:1
    (0000035075) _____________ error: 13

    (0000035520) Memory Available = 35428592 <14784>
    (0000038686) Error sending UDP packet (IP=EFFFFAFB) (Error=65)
    (0000045084) SendString to socket-unknown sendto error 0x0
    (0000045085) CIpEvent::OnError 0:16:1
    (0000045085) _____________ error: 13

    (0000045817) Error sending UDP packet (IP=EFFFFAFB) (Error=65)
    (0000049373) *** ndvMC_Server string [10.0.0.160]
    (0000053965) Error sending UDP packet (IP=EFFFFAFB) (Error=65)
    (0000070511) Memory Available = 35413072 <15520>
    (0000070922) (Reader=tInterpreter writer=tSMUDPRx15)- CMessagePipe::Max = 25
    (0000076526) Memory Available = 35399728 <13344>
    (0000116034) Error sending UDP packet (IP=EFFFFAFB) (Error=65)
  • jimmywjimmyw Junior Member Posts: 112
    the source of all your errors is this guy
    "(0000028201) IPDeviceDetector.run(): failed to join multicast group"

    Try this

    change the following lines
    
    wait 90 IP_CLIENT_OPEN (ndvMC_Client.Port,'239.255.255.250',1900,IP_UDP_2WAY)
    //wait 100 IP_MC_SERVER_OPEN(ndvMC_Server.port,'239.255.255.250',1900)
    
    DEFINE_EVENT
    
    DATA_EVENT[ndvMC_Client]{
        ONLINE:{
    etc
    etc
    

    I forgot about the netlinx issue of not being able to open 2 connections to the same IP, which I assume this is hitting, even though its multicast.
  • alexander77alexander77 Junior Member Posts: 17
    Jimmy,

    many thanks for your help, its working now.

    The problem with the multicast group was an error in the ip-settings of the second master, it was 192.186.xxx.xxx
    It's also working with client and server, looks like multicast is able to run both server and client on the same ip address.


    Welcome to NetLinx v3.60.453 Copyright AMX LLC 2010
    >msg on all
    All Extended diagnostic information messages turned on.
    >(0000023333) 08:19:14.583 EVENT Started ServletHttpContext[/]
    (0000023337) DynamicServlet 0.0.1 has been started
    (0000023383) 08:19:14.633 EVENT Starting Jetty/4.2.x
    (0000023610) 08:19:14.866 EVENT Started SocketListener on 0.0.0.0:80
    (0000024408) 08:19:15.666 EVENT Started SocketListener on 0.0.0.0:443
    (0000024411) 08:19:15.666 EVENT Started [email protected]
    (0000024505) Memory Available = 35467528 <489840>
    (0000024582) CIpInterpreter::Run - Execute Startup Code
    (0000025072) CIpEvent::OnLine 0:1:1
    (0000025073) CIpEvent::OnLine 5001:1:1
    (0000025073) CIpEvent::OnLine 5001:2:1
    (0000025074) CIpEvent::OnLine 5001:3:1
    (0000025074) CIpEvent::OnLine 5001:4:1
    (0000025075) CIpEvent::OnLine 5001:5:1
    (0000025075) CIpEvent::OnLine 5001:6:1
    (0000025075) CIpEvent::OnLine 5001:7:1
    (0000025076) CIpEvent::OnLine 5001:8:1
    (0000025076) CIpEvent::OnLine 5001:9:1
    (0000025077) CIpEvent::OnLine 5001:10:1
    (0000025077) CIpEvent::OnLine 5001:11:1
    (0000025078) CIpEvent::OnLine 5001:12:1
    (0000025078) CIpEvent::OnLine 5001:13:1
    (0000025080) CIpEvent::OnLine 5001:14:1
    (0000025084) CIpEvent::OnLine 5001:15:1
    (0000025088) CIpEvent::OnLine 5001:16:1
    (0000025092) CIpEvent::OnLine 5001:17:1
    (0000028217) IPDeviceDetector.run(): joined multicast group
    (0000028504) Memory Available = 35454048 <13480>
    (0000034070) CIpEvent::OnLine 0:16:1
    (0000034502) Memory Available = 35443376 <10672>
    (0000035071) CIpEvent::OnLine 0:15:1
    (0000035072) ndvMC_Server online
    (0000035073) *** ndvMC_Server string [192.168.0.110]
    (0000035073) *** ndvMC_Server string [192.168.0.110]
    (0000035502) Memory Available = 35428592 <14784>
    (0000045084) *** ndvMC_Server string [192.168.0.110]
    (0000055082) *** ndvMC_Server string [192.168.0.110]
    (0000065079) *** ndvMC_Server string [192.168.0.110]
    (0000075077) *** ndvMC_Server string [192.168.0.110]
    (0000085074) *** ndvMC_Server string [192.168.0.110]
    (0000095072) *** ndvMC_Server string [192.168.0.110]
    (0000105070) *** ndvMC_Server string [192.168.0.110]
    (0000115067) *** ndvMC_Server string [192.168.0.110]
    (0000125065) *** ndvMC_Server string [192.168.0.110]
    (0000135062) *** ndvMC_Server string [192.168.0.110]


    Cheers,

    Alexander
  • jimmywjimmyw Junior Member Posts: 112
    Glad I could help :)
Sign In or Register to comment.