Created
March 5, 2013 23:12
-
-
Save joshareed/5095234 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// simulates random messages from a contact sensor via socket to dev-conn | |
RANDOM = new Random() | |
MESSAGES = [ | |
"zone report :: type: 19 value: 0031", | |
"zone report :: type: 19 value: 0030" | |
] | |
ENV = [ | |
josh: [ | |
host: 'localhost', | |
port: 9000, | |
device: '7b06', | |
hub: 'virtual-357816be-7234-4258-b1bc-4540ce29f18f' | |
], | |
dev: [ | |
host: 'dev-device-conn-lb-1817678842.us-east-1.elb.amazonaws.com', | |
device: 'b711', | |
hub: 'virtual-6cbba9b8-483d-4744-be9f-02ab207d4f84' | |
], | |
staging: [ | |
host: 'ec2-50-16-103-108.compute-1.amazonaws.com', | |
device: '9214', | |
hub: 'virtual-c7a35c11-6df6-4532-9d9d-5be7574f27ea' | |
], | |
prod: [ | |
host: 'production-device-conn-lb-1001321349.us-east-1.elb.amazonaws.com', | |
device: 'a568', | |
hub: 'virtual-c7a35c11-6df6-4532-9d9d-5be7574f27ea' | |
] | |
] | |
if (!args) { | |
println "Usage: groovy SimulateContactSensorDevConn.groovy {dev,staging,prod}" | |
System.exit(1) | |
} | |
// grab our environment | |
env = ENV[args[0]] | |
if (!env) { | |
println "'${args[0]}' is not a valid environment, please use 'dev', 'staging', or 'prod'" | |
println "Usage: groovy SimulateContactSensorDevConn.groovy {dev,staging,prod}" | |
System.exit(1) | |
} | |
socket = new Socket(env.host, env.port ?: 9090) | |
socket.withStreams { input, output -> | |
def reader = input.newReader() | |
println "Registering as ${env.hub}" | |
output << "register ${env.hub}\n".toString() | |
println reader.readLine() | |
while(true) { | |
String msg = MESSAGES[RANDOM.nextInt(MESSAGES.size())] | |
output << """{"h":"${env.hub}","dni":"${env.device}","data":"${msg}"}\n""".toString() | |
println reader.readLine() | |
Thread.sleep(RANDOM.nextInt(1000) + 1000) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment