This repository has been archived by the owner on Oct 3, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
working on iot device status change message sender (is that a word?)
- Loading branch information
fulton
committed
Dec 30, 2019
1 parent
f29c296
commit 4010387
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,34 @@ | ||
package com.andromeda.araserver.iot | ||
|
||
import com.microsoft.azure.sdk.iot.service.* | ||
|
||
|
||
class SendData { | ||
private val protocol = IotHubServiceClientProtocol.AMQPS | ||
|
||
fun main(connectionString: String, deviceId:String){ | ||
val serviceClient = ServiceClient.createFromConnectionString( | ||
connectionString, protocol | ||
) | ||
|
||
if (serviceClient != null) { | ||
serviceClient.open() | ||
val feedbackReceiver = serviceClient | ||
.feedbackReceiver | ||
feedbackReceiver?.open() | ||
val messageToSend = Message("Cloud to device message.") | ||
messageToSend.deliveryAcknowledgement = DeliveryAcknowledgement.Full | ||
serviceClient.send(deviceId, messageToSend) | ||
println("Message sent to device") | ||
val feedbackBatch = feedbackReceiver!!.receive(10000) | ||
if (feedbackBatch != null) { | ||
println( | ||
"Message feedback received, feedback time: " | ||
+ feedbackBatch.enqueuedTimeUtc.toString() | ||
) | ||
} | ||
feedbackReceiver?.close() | ||
serviceClient.close() | ||
} | ||
} | ||
} |