Skip to content
This repository has been archived by the owner on Oct 3, 2020. It is now read-only.

Commit

Permalink
working on iot device status change message sender (is that a word?)
Browse files Browse the repository at this point in the history
  • Loading branch information
fulton committed Dec 30, 2019
1 parent f29c296 commit 4010387
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ plugins {
application {
mainClassName('com.andromeda.araserver.Run')
}
version = 1.8
sourceCompatibility = 1.8
mainClassName = 'com.andromeda.araserver.Run'
jar {
manifest {
Expand Down Expand Up @@ -52,6 +54,7 @@ dependencies {
compile 'org.hibernate:hibernate-agroal:5.4.10.Final'
implementation"com.squareup.okhttp3:okhttp:4.2.0"
implementation 'com.microsoft.azure:azure-documentdb:2.4.5'
compile group: 'com.microsoft.azure.sdk.iot', name: 'iot-service-client', version: '1.19.0'
implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.10.1'
compile group: 'org.apache.opennlp', name: 'opennlp-tools', version: '1.9.2'
compile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '7.4.1.jre11'
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/com/andromeda/araserver/iot/SendData.kt
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()
}
}
}

0 comments on commit 4010387

Please sign in to comment.