tidy up things Project: http://git-wip-us.apache.org/repos/asf/incubator-edgent/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-edgent/commit/5647338d Tree: http://git-wip-us.apache.org/repos/asf/incubator-edgent/tree/5647338d Diff: http://git-wip-us.apache.org/repos/asf/incubator-edgent/diff/5647338d
Branch: refs/heads/master Commit: 5647338d365ee23745cffb9b020fd113fd9f6aca Parents: 65ef2cb Author: Dale LaBossiere <[email protected]> Authored: Sun Feb 26 15:02:15 2017 -0500 Committer: Dale LaBossiere <[email protected]> Committed: Sun Feb 26 15:02:15 2017 -0500 ---------------------------------------------------------------------- RELEASE_NOTES | 3 +- .../samples/connectors/iotp/IotpAppClient.java | 2 +- .../connectors/iotp/IotpDeviceSample.java | 16 +++---- .../connectors/iotp/IotpGWDeviceSample.java | 45 +++++++++----------- scripts/connectors/iotp/README | 36 ++++++++++++++++ 5 files changed, 66 insertions(+), 36 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/5647338d/RELEASE_NOTES ---------------------------------------------------------------------- diff --git a/RELEASE_NOTES b/RELEASE_NOTES index fc59787..d9dba00 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -15,6 +15,7 @@ workspace. See DEVELOPMENT.md for information about building Edgent. New Features -------------------- EDGENT-377 Add IotGateway and IotpGateway + This feature is incubating. See the classes Javadoc. EDGENT-376 Support an edge device using both the Edgent API and WIoTP "Managed Device" APIs EDGENT-375 Support publishing WIoTP device events using HTTP EDGENT-370 Add static IotProvider.getPreferences() @@ -26,7 +27,7 @@ None Known Issues -------- -None yet +Open JIRAs may be found at https://issues.apache.org/jira/browse/EDGENT Bug Fixes --------- http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/5647338d/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/iotp/IotpAppClient.java ---------------------------------------------------------------------- diff --git a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/iotp/IotpAppClient.java b/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/iotp/IotpAppClient.java index 959f218..adc7a8f 100644 --- a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/iotp/IotpAppClient.java +++ b/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/iotp/IotpAppClient.java @@ -126,7 +126,7 @@ public class IotpAppClient { jo.addProperty("num", 12345); JsonObject data = jo; - System.out.println("Sending "+iotpDevType+"/"+iotpDevId+" command: "+command+" data("+data.getClass().getName()+")="+data); + System.out.println("Sending "+iotpDevType+"/"+iotpDevId+" command: "+command+" data: "+data); boolean ok = client.publishCommand(iotpDevType, iotpDevId, command, data); http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/5647338d/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/iotp/IotpDeviceSample.java ---------------------------------------------------------------------- diff --git a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/iotp/IotpDeviceSample.java b/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/iotp/IotpDeviceSample.java index a88dfe1..755890f 100644 --- a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/iotp/IotpDeviceSample.java +++ b/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/iotp/IotpDeviceSample.java @@ -39,11 +39,10 @@ import com.ibm.iotf.devicemgmt.device.ManagedDevice; /** * Similar to IotpQuickstart2 but for a real/non-quickstart WIoTP account - * for a registered device - * AND it subscribes to/prints device cmds. + * for a registered device AND it subscribes to/prints device cmds. * <P> - * Use IotpAppClient or any other technique to generate cmds. - * e.g., mosquitto_{pub,sub} cmds are printed below. + * Use IotpAppClient to print published events and generate a command + * (start this app before running IotpAppClient). * <P> * This sample demonstrates: * <UL> @@ -85,12 +84,8 @@ public class IotpDeviceSample { System.out.println("DeviceType: " + iotpDevType); System.out.println("DeviceId: " + iotpDevId); - System.out.println("device clientId: " + "d:"+iotpOrg+":"+iotpDevType+":"+iotpDevId); - System.out.println("WIoTP host: " + iotpOrg+".messaging.internetofthings.ibmcloud.com"); - System.out.println("evt topic: " + "iot-2/type/"+iotpDevType+"/id/"+iotpDevId+"/evt/+/fmt/json"); - System.out.println("cmd topic: " + "iot-2/type/"+iotpDevType+"/id/"+iotpDevId+"/cmd/+/fmt/json"); - System.out.println("mosquitto_pub -u <api-auth-key> -P <api-quth-token> -h "+iotpOrg+".messaging.internetofthings.ibmcloud.com -p 1883 -i a:"+iotpOrg+":appId1 -t iot-2/type/"+iotpDevType+"/id/"+iotpDevId+"/cmd/cmd-1/fmt/json -m '{}'"); - System.out.println("mosquitto_sub -d -u <api-auth-key> -P <api-quth-token> -h "+iotpOrg+".messaging.internetofthings.ibmcloud.com -p 1883 -i a:"+iotpOrg+":appId2 -t iot-2/type/+/id/+/evt/+/fmt/+"); + // System.out.println("mosquitto_pub -u <api-auth-key> -P <api-quth-token> -h "+iotpOrg+".messaging.internetofthings.ibmcloud.com -p 1883 -i a:"+iotpOrg+":appId1 -t iot-2/type/"+iotpDevType+"/id/"+iotpDevId+"/cmd/cmd-1/fmt/json -m '{}'"); + // System.out.println("mosquitto_sub -d -u <api-auth-key> -P <api-quth-token> -h "+iotpOrg+".messaging.internetofthings.ibmcloud.com -p 1883 -i a:"+iotpOrg+":appId2 -t iot-2/type/+/id/+/evt/+/fmt/+"); IotpDevice device; if (useInternalDeviceClient) { @@ -136,6 +131,7 @@ public class IotpDeviceSample { device.httpEvents(json, "sensors"); } + // subscribe to / report device cmds device.commands().sink(jo -> System.out.println("Received cmd: " + jo)); tp.submit(topology); http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/5647338d/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/iotp/IotpGWDeviceSample.java ---------------------------------------------------------------------- diff --git a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/iotp/IotpGWDeviceSample.java b/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/iotp/IotpGWDeviceSample.java index da665a8..c03ed25 100644 --- a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/iotp/IotpGWDeviceSample.java +++ b/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/iotp/IotpGWDeviceSample.java @@ -44,10 +44,10 @@ import com.ibm.iotf.devicemgmt.gateway.ManagedGateway; /** * Similar to IotpQuickstart2 but for a real/non-quickstart WIoTP account * and a registered IoT Gateway device with connected devices - * AND it subscribes to/prints device cmds. + * AND it subscribes to and prints received device cmds. * <P> - * Use IotpAppClient or any other technique to generate cmds. - * e.g., mosquitto_{pub,sub} cmds are printed below. + * Use IotpAppClient to print published events and generate a command + * (start this app before running IotpAppClient with the "useGW" option). * <P> * This sample demonstrates: * <UL> @@ -87,23 +87,18 @@ public class IotpGWDeviceSample { String iotpOrg = getProperty(cfgProps, "Organization-ID", "org"); String iotpGWDevType = getProperty(cfgProps, "Gateway-Type", "Device-Type", "type"); String iotpGWDevId = getProperty(cfgProps, "Gateway-ID", "Device-ID", "id"); + String iotpCnDev1Type = cfgProps.getProperty("cn-dev1-type"); + String iotpCnDev1Id = cfgProps.getProperty("cn-dev1-id"); + System.out.println("orgId: " + iotpOrg); System.out.println("GWDeviceType: " + iotpGWDevType); System.out.println("GWDeviceId: " + iotpGWDevId); + System.out.println("cn-dev1 DeviceType: " + iotpCnDev1Type); + System.out.println("cn-dev1 DeviceId: " + iotpCnDev1Id); - System.out.println("GW device clientId: " + "g:"+iotpOrg+":"+iotpGWDevType+":"+iotpGWDevId); - System.out.println("WIoTP host: " + iotpOrg+".messaging.internetofthings.ibmcloud.com"); - System.out.println("GW evt topic: " + "iot-2/type/"+iotpGWDevType+"/id/"+iotpGWDevId+"/evt/+/fmt/json"); - System.out.println("GW cmd topic: " + "iot-2/type/"+iotpGWDevType+"/id/"+iotpGWDevId+"/cmd/+/fmt/json"); - System.out.println("GW mosquitto_pub -u <api-auth-key> -P <api-auth-token> -h "+iotpOrg+".messaging.internetofthings.ibmcloud.com -p 1883 -i a:"+iotpOrg+":appId1 -t iot-2/type/"+iotpGWDevType+"/id/"+iotpGWDevId+"/cmd/cmd-1/fmt/json -m '{}'"); - System.out.println("GW mosquitto_sub -d -u <api-auth-key> -P <api-auth-token> -h "+iotpOrg+".messaging.internetofthings.ibmcloud.com -p 1883 -i a:"+iotpOrg+":appId2 -t iot-2/type/+/id/+/evt/+/fmt/+"); - - String iotpCnDev1Type = cfgProps.getProperty("cn-dev1-type"); - String iotpCnDev1Id = cfgProps.getProperty("cn-dev1-id"); - System.out.println("cn-dev1 clientId: " + "d:"+iotpOrg+":"+iotpCnDev1Type+":"+iotpCnDev1Id); - System.out.println("cn-dev1 evt topic: " + "iot-2/type/"+iotpCnDev1Type+"/id/"+iotpCnDev1Id+"/evt/+/fmt/json"); - System.out.println("cn-dev1 cmd topic: " + "iot-2/type/"+iotpCnDev1Type+"/id/"+iotpCnDev1Id+"/cmd/+/fmt/json"); - System.out.println("cn-dev1 mosquitto_pub -u <api-auth-key> -P <api-quth-token> -h "+iotpOrg+".messaging.internetofthings.ibmcloud.com -p 1883 -i a:"+iotpOrg+":appId1 -t iot-2/type/"+iotpCnDev1Type+"/id/"+iotpCnDev1Id+"/cmd/cmd-1/fmt/json -m '{}'"); + // System.out.println("GW mosquitto_pub -u <api-auth-key> -P <api-auth-token> -h "+iotpOrg+".messaging.internetofthings.ibmcloud.com -p 1883 -i a:"+iotpOrg+":appId1 -t iot-2/type/"+iotpGWDevType+"/id/"+iotpGWDevId+"/cmd/cmd-1/fmt/json -m '{}'"); + // System.out.println("GW mosquitto_sub -d -u <api-auth-key> -P <api-auth-token> -h "+iotpOrg+".messaging.internetofthings.ibmcloud.com -p 1883 -i a:"+iotpOrg+":appId2 -t iot-2/type/+/id/+/evt/+/fmt/+"); + // System.out.println("cn-dev1 mosquitto_pub -u <api-auth-key> -P <api-quth-token> -h "+iotpOrg+".messaging.internetofthings.ibmcloud.com -p 1883 -i a:"+iotpOrg+":appId1 -t iot-2/type/"+iotpCnDev1Type+"/id/"+iotpCnDev1Id+"/cmd/cmd-1/fmt/json -m '{}'"); IotpGateway gwDevice; if (useInternalGatewayClient) { @@ -121,16 +116,17 @@ public class IotpGWDeviceSample { } else throw new IllegalStateException("woops"); - - - System.out.println("GW fqDeviceId: " + gwDevice.getDeviceId()); Map<String,String> devAttrMap = new HashMap<>(); devAttrMap.put(IotpGateway.ATTR_DEVICE_TYPE, iotpCnDev1Type); devAttrMap.put(IotpGateway.ATTR_DEVICE_ID, iotpCnDev1Id); + String cnDev1FqDeviceId = gwDevice.getIotDeviceId(devAttrMap); IotDevice cnDev1Device = gwDevice.getIotDevice(cnDev1FqDeviceId); + + System.out.println("GW fqDeviceId: " + gwDevice.getDeviceId()); System.out.println("cn-dev1 fqDeviceId: " + cnDev1FqDeviceId); + System.out.println("IotDevice cn-dev1 fqDeviceId: " + cnDev1Device.getDeviceId()); Random r = new Random(); TStream<double[]> raw = topology.poll(() -> { @@ -167,20 +163,21 @@ public class IotpGWDeviceSample { else { System.out.println("Publishing events using HTTP"); throw new IllegalStateException("GW httpEvents is NYI"); - // device.httpEvents(json, "sensors"); + // gwDevice.httpEvents(json, "sensors"); + // gwDevice.httpEventsForDevice(cnDev1FqDeviceId, cnDev1Json, "gw-events-for-cnDev1"); } - // should report cmds for ALL devices - gw+dev + // subscribe to / report cmds for the GW and all its connected devices gwDevice.commandsForDevice(Collections.emptySet()).sink(jo -> System.out.println("Received all-cmds cmd: " + jo)); - // just GW device cmds + // subscribe to / report just GW device cmds gwDevice.commands().sink(jo -> System.out.println("Received gwDevice cmd: " + jo)); - // just cnDev1 device cmds + // subscribe to / report just cnDev1 device cmds gwDevice.commandsForDevice(cnDev1FqDeviceId).sink(jo -> System.out.println("Received gwDevice-for-cnDev1 cmd: " + jo)); cnDev1Device.commands().sink(jo -> System.out.println("Received cnDev1 cmd: " + jo)); - // just cmds for a specific device type + // subscribe to / report just cmds for a specific device type gwDevice.commandsForType(iotpGWDevType).sink(jo -> System.out.println("Received for-type-gwDeviceType cmd: " + jo)); gwDevice.commandsForType(iotpCnDev1Type).sink(jo -> System.out.println("Received for-type-cnDev1DeviceType cmd: " + jo)); http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/5647338d/scripts/connectors/iotp/README ---------------------------------------------------------------------- diff --git a/scripts/connectors/iotp/README b/scripts/connectors/iotp/README new file mode 100644 index 0000000..0eaee83 --- /dev/null +++ b/scripts/connectors/iotp/README @@ -0,0 +1,36 @@ + +# ########## +# The "Quickstart" samples connect to the IBM Watson IoT Platform +# using the Quickstart feature that does not require device registration. +# When the samples are run they print out a URL which allows a browser +# to see the data being sent from this sample. +# +# IotpQuickstart2 demonstrates using the WIoTP API to initialize the IotpDevice +# connector as well as the ability to publish events using the WIoTP HTTP protocol. + +IotpQuickstart - ./runquickstart.sh +IotpQuickstart2 - ./runquickstart2.sh [useHttp] + +# ########## +# IotpSensors connects to your IBM Watson IoT Platform service +# as the device defined in your device config file. +# +# A sample config file for your WIoTP registered device information +# is provided in device.cfg. + +IotpSensors - ./runiotsensors.sh device-cfg-path + +# ########## +# IotpDeviceSample and IotpGatewaySample +# connect to your IBM Watson IoT Platform service. +# They publish device events and print out received device commands. +# Use IotpAppClient to print out the generated device events and +# to generate the device commands. +# +# Sample config files for your WIoTP registered device, gateway, +# and application client information are provided in +# iotp-device-sample.cfg, iotp-gwdevice-sample.cfg and iotp-app-client.cfg + +IotpDeviceSample - ./run-iotp-device-sample.sh [useDeviceClient|useManagedDevice] [useHttp] <device-cfg-path> +IotpGatewaySample - ./run-iotp-gwdevice-sample.sh [useGatewayClient|useManagedGateway] [useHttp] <device-cfg-path> +IotpAppClient - ./run-iotp-client-app.sh [useGW] <app-cfg-path> \ No newline at end of file
