Skip to content

Commit dc4724d

Browse files
committed
Update to IoT samples
1 parent 7ccd3e5 commit dc4724d

File tree

9 files changed

+56
-28
lines changed

9 files changed

+56
-28
lines changed

IoT-Sample/Swift/IoTSampleSwift/AppDelegate.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2323

2424
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
2525
// Override point for customization after application launch.
26-
let credentialProvider = AWSCognitoCredentialsProvider(regionType: AwsRegion, identityPoolId: CognitoIdentityPoolId)
2726

28-
let configuration = AWSServiceConfiguration(
29-
region: AwsRegion,
30-
credentialsProvider: credentialProvider)
31-
32-
AWSServiceManager.default().defaultServiceConfiguration = configuration
27+
//Setting up logging to xcode console.
28+
AWSDDLog.sharedInstance.logLevel = .debug
29+
AWSDDLog.add(AWSDDTTYLogger.sharedInstance)
3330

3431
return true
3532
}

IoT-Sample/Swift/IoTSampleSwift/ConnectionViewController.swift

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ class ConnectionViewController: UIViewController, UITextViewDelegate {
231231
override func viewDidLoad() {
232232
super.viewDidLoad()
233233
// Do any additional setup after loading the view, typically from a nib.
234-
235234
let tabBarViewController = tabBarController as! IoTSampleTabBarController
236235
publishViewController = tabBarViewController.viewControllers![1]
237236
subscribeViewController = tabBarViewController.viewControllers![2]
@@ -245,16 +244,25 @@ class ConnectionViewController: UIViewController, UITextViewDelegate {
245244
// Set up Cognito
246245
//
247246
let credentialsProvider = AWSCognitoCredentialsProvider(regionType: AwsRegion, identityPoolId: CognitoIdentityPoolId)
248-
let configuration = AWSServiceConfiguration(region: AwsRegion, credentialsProvider: credentialsProvider)
249-
250-
AWSServiceManager.default().defaultServiceConfiguration = configuration
247+
let iotEndPoint = AWSEndpoint(urlString: IOT_ENDPOINT)
248+
//configuration for AWSIoT control plane APIs
249+
let iotConfiguration = AWSServiceConfiguration(region: AwsRegion,
250+
credentialsProvider: credentialsProvider)
251+
//configuration for AWSIoT Data plane APIs
252+
let iotDataConfiguration = AWSServiceConfiguration(region: AwsRegion,
253+
endpoint: iotEndPoint,
254+
credentialsProvider: credentialsProvider)
255+
AWSServiceManager.default().defaultServiceConfiguration = iotConfiguration
251256

252257
iotManager = AWSIoTManager.default()
253258
iot = AWSIoT.default()
254-
255-
iotDataManager = AWSIoTDataManager.default()
256-
iotData = AWSIoTData.default()
257-
259+
260+
AWSIoTDataManager.register(with: iotDataConfiguration!, forKey: "MyIotDataManager")
261+
iotDataManager = AWSIoTDataManager(forKey: "MyIotDataManager")
262+
263+
AWSIoTData.register(with: iotDataConfiguration!, forKey: "MyIotData")
264+
iotData = AWSIoTData(forKey: "MyIotData")
265+
258266
}
259267

260268
override func didReceiveMemoryWarning() {

IoT-Sample/Swift/IoTSampleSwift/Constants.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ let CertificateSigningRequestCountryName = "Your Country"
2424
let CertificateSigningRequestOrganizationName = "Your Organization"
2525
let CertificateSigningRequestOrganizationalUnitName = "Your Organizational Unit"
2626
let PolicyName = "YourPolicyName"
27+
//This is the endpoint in your AWS IoT console. eg: https://xxxxxxxxxx.iot.<region>.amazonaws.com
28+
let IOT_ENDPOINT = "https://xxxxxxxxxx.iot.<region>.amazonaws.com"

IoT-Sample/Swift/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ This sample demonstrates use of the AWS IoT APIs to securely publish to and subs
3636
let CertificateSigningRequestOrganizationName = "Your Organization"
3737
let CertificateSigningRequestOrganizationalUnitName = "Your Organizational Unit"
3838
let PolicyName = "YourPolicyName"
39+
let IOT_ENDPOINT = "https://xxxxxxxxxx.iot.<region>.amazonaws.com"
3940
```
4041

4142
1. Build and run the sample app.

IoTTemperatureControl-Sample/Swift/IoTTemperatureControlSample/AppDelegate.swift

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2323

2424

2525
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
26-
//
27-
// Use Cognito authentication
28-
//
29-
let credentialProvider = AWSCognitoCredentialsProvider(regionType: AwsRegion, identityPoolId: CognitoIdentityPoolId)
30-
31-
let configuration = AWSServiceConfiguration(
32-
region: AwsRegion,
33-
credentialsProvider: credentialProvider)
34-
35-
AWSServiceManager.default().defaultServiceConfiguration = configuration
26+
//Setup logging to xcode console.
27+
AWSDDLog.sharedInstance.logLevel = .debug
28+
AWSDDLog.add(AWSDDTTYLogger.sharedInstance)
3629

3730
return true
3831
}

IoTTemperatureControl-Sample/Swift/IoTTemperatureControlSample/Constants.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ import AWSCore
2121
//
2222
let AwsRegion = AWSRegionType.Unknown // e.g. AWSRegionType.USEast1
2323
let CognitoIdentityPoolId = "YourCognitoIdentityPoolId"
24+
//This is the endpoint in your AWS IoT console. eg: https://xxxxxxxxxx.iot.<region>.amazonaws.com
25+
let IOT_ENDPOINT = "https://xxxxxxxxxx.iot.<region>.amazonaws.com"

IoTTemperatureControl-Sample/Swift/IoTTemperatureControlSample/ViewController.swift

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,16 @@ class ViewController: UIViewController {
117117
currentlyEnabled = enabled;
118118
}
119119
}
120+
func thingShadowTimeoutCallback( _ thingName: String, json: JSON, payloadString: String ) -> Void {
121+
if (thingName == controlThingName)
122+
{
123+
controlThingOperationInProgress = false;
124+
}
125+
else // thingName == statusThingName
126+
{
127+
statusThingOperationInProgress = false;
128+
}
129+
}
120130
func thingShadowDeltaCallback( _ thingName: String, json: JSON, payloadString: String ) -> Void {
121131
if (thingName == controlThingName)
122132
{
@@ -180,6 +190,7 @@ class ViewController: UIViewController {
180190
self.thingShadowDeltaCallback( name, json: json, payloadString: stringValue as! String)
181191
case .timeout:
182192
print("timeout on \(name)")
193+
self.thingShadowTimeoutCallback( name, json: json, payloadString: stringValue as! String)
183194

184195
default:
185196
print("unknown operation status: \(operationStatus.rawValue)")
@@ -249,12 +260,25 @@ class ViewController: UIViewController {
249260
// Initialize the status switch
250261
//
251262
statusSwitch.isOn=true
252-
263+
264+
//
265+
// Use Cognito authentication
266+
//
267+
let credentialProvider = AWSCognitoCredentialsProvider(regionType: AwsRegion, identityPoolId: CognitoIdentityPoolId)
268+
let iotEndPoint = AWSEndpoint(urlString: IOT_ENDPOINT)
269+
let iotDataConfiguration = AWSServiceConfiguration(
270+
region: AwsRegion,
271+
endpoint: iotEndPoint,
272+
credentialsProvider: credentialProvider)
273+
253274
//
254275
// Init IOT
255276
//
256-
iotDataManager = AWSIoTDataManager.default()
257-
277+
278+
AWSIoTDataManager.register(with: iotDataConfiguration!, forKey: "MyIotDataManager")
279+
iotDataManager = AWSIoTDataManager(forKey: "MyIotDataManager")
280+
281+
258282
#if DEMONSTRATE_LAST_WILL_AND_TESTAMENT
259283
//
260284
// Set a Last Will and Testament message in the MQTT configuration; other

IoTTemperatureControl-Sample/Swift/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ platform :ios, '8.0'
44
use_frameworks!
55

66
target 'IoTTemperatureControlSample' do
7-
pod 'AWSIoT', ''~>2.5.0'
7+
pod 'AWSIoT', '~>2.5.0'
88
pod 'SwiftyJSON'
99
end

IoTTemperatureControl-Sample/Swift/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ This sample demonstrates use of the AWS IoT MQTT device shadow APIs over a WebSo
3131
```c
3232
let AwsRegion = AWSRegionType.Unknown // e.g. AWSRegionType.USEast1
3333
let CognitoIdentityPoolId = "YourCognitoIdentityPoolId"
34+
let IOT_ENDPOINT = "https://xxxxxxxxxx.iot.<region>.amazonaws.com"
3435
```
3536
1. Install the [AWS IoT JavaScript SDK for Embedded Devices](https://github.com/aws/aws-iot-device-sdk-js).
3637

0 commit comments

Comments
 (0)