-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
45 lines (39 loc) · 1.32 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"fmt"
"log"
"os"
"github.com/tappoz/azure-golang-iothub/iothub"
)
func main() {
connectionString := os.Getenv("CONNECTION_STRING")
if connectionString == "" {
log.Fatal("No CONNECTION_STRING in environment")
}
client, err := iothub.NewIotHubHTTPClientFromConnectionString(connectionString)
if err != nil {
log.Fatalln("Error creating http client from connection string", err)
}
defaultDeviceID := "testDevice1"
if !client.IsDevice() {
log.Printf("No DeviceId in connection string, running provisioning test.")
resp, status := client.ListDeviceIDs(10)
log.Printf("%s, %s\n\n", resp, status)
resp, status = client.CreateDeviceID(defaultDeviceID)
log.Printf("%s, %s\n\n", resp, status)
resp, status = client.GetDeviceID(defaultDeviceID)
log.Printf("%s, %s\n\n", resp, status)
resp, status = client.PurgeCommandsForDeviceID(defaultDeviceID)
log.Printf("%s, %s\n\n", resp, status)
//resp, status = DeleteDeviceID(hub, defaultDeviceID)
//log.Printf("%s, %s\n\n", resp, status)
} else {
log.Printf("DeviceID defined in connection string, running message test.")
resp, status := client.ReceiveMessage()
log.Printf("%s, %s\n\n", resp, status)
for i := 0; i < 10; i++ {
resp, status = client.SendMessage(fmt.Sprintf(`{"count":%d}`, i))
log.Printf("%s, %s\n\n", resp, status)
}
}
}