Skip to content

Commit 45e90bc

Browse files
authored
Merge pull request #74 from PTCInc/feat_add_iot_gateway_support
Feat add iot gateway support
2 parents 344cd17 + 24d9355 commit 45e90bc

29 files changed

Lines changed: 5231 additions & 6 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ docs/docfx/api/
88
docs/docfx/_*
99
docs/docfx/Kepware*
1010
docs/docfx/*.md
11+
.API *
1112

1213
# User-specific files
1314
*.rsuser

Kepware.Api.Sample/Program.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,47 @@ static async Task Main(string[] args)
5757

5858
await api.Project.Devices.UpdateDeviceAsync(device, true);
5959

60+
// --- IoT Gateway: MQTT Client Agent ---
61+
var mqttAgent = await api.Project.IotGateway.GetOrCreateMqttClientAgentAsync("MQTT Agent by Api");
62+
mqttAgent.Url = "tcp://broker.example.com:1883";
63+
mqttAgent.Topic = "kepware/data";
64+
await api.Project.IotGateway.UpdateMqttClientAgentAsync(mqttAgent);
65+
66+
// Add an IoT Item referencing a tag on the device created above
67+
var mqttItem = await api.Project.IotGateway.GetOrCreateIotItemAsync(
68+
$"{channel1.Name}.{device.Name}.BooleanByApi", mqttAgent);
69+
mqttItem.ScanRateMs = 500;
70+
await api.Project.IotGateway.UpdateIotItemAsync(mqttItem);
71+
72+
// Clean up MQTT IoT Item and agent
73+
await api.Project.IotGateway.DeleteIotItemAsync(mqttItem);
74+
await api.Project.IotGateway.DeleteMqttClientAgentAsync(mqttAgent);
75+
76+
// --- IoT Gateway: REST Client Agent ---
77+
var restClientAgent = await api.Project.IotGateway.GetOrCreateRestClientAgentAsync("REST Client by Api");
78+
restClientAgent.Url = "https://api.example.com/data";
79+
restClientAgent.HttpMethod = RestClientHttpMethod.Post;
80+
await api.Project.IotGateway.UpdateRestClientAgentAsync(restClientAgent);
81+
82+
// Add an IoT Item to the REST Client agent
83+
var restClientItem = await api.Project.IotGateway.GetOrCreateIotItemAsync(
84+
$"{channel1.Name}.{device.Name}.SineByApi", restClientAgent);
85+
await api.Project.IotGateway.DeleteIotItemAsync(restClientItem);
86+
await api.Project.IotGateway.DeleteRestClientAgentAsync(restClientAgent);
87+
88+
// --- IoT Gateway: REST Server Agent ---
89+
var restServerAgent = await api.Project.IotGateway.GetOrCreateRestServerAgentAsync("REST Server by Api");
90+
restServerAgent.PortNumber = 39321;
91+
restServerAgent.EnableWriteEndpoint = true;
92+
await api.Project.IotGateway.UpdateRestServerAgentAsync(restServerAgent);
93+
94+
// Add an IoT Item to the REST Server agent
95+
var restServerItem = await api.Project.IotGateway.GetOrCreateIotItemAsync(
96+
$"{channel1.Name}.{device.Name}.RampByApi", restServerAgent);
97+
await api.Project.IotGateway.DeleteIotItemAsync(restServerItem);
98+
await api.Project.IotGateway.DeleteRestServerAgentAsync(restServerAgent);
99+
100+
// Clean up channel and device
60101
await api.Project.Devices.DeleteDeviceAsync(device);
61102
await api.Project.Channels.DeleteChannelAsync(channel1);
62103

0 commit comments

Comments
 (0)