Reputation: 41
I have a project I want to do that involves an Arduino that sends serial data to a Raspberry Pi, And the Raspberry Pi displays the data to a screen and updates an API. I want a desktop application that also displays the data that was sent to the API. To get a feel for the technologies, initially the only data sent is going to be a the state of a stopwatch timer that runs on the Raspberry Pi, IE running vs stopped. I know it would be simple to hit the API periodically from the application to retrieve new data, But I want the application to be updated when the API receives new information. I was thinking some sort of a subscriber system where the applications I want updated can subscribe to the API and will be updated all at the same time.
The API will be written in dot net core 2.2. The desktop application will be written using WPF in dot net framework 4.7.2. Other languages or frameworks used for the Arduino or Raspberry Pi are not relevant.
How do I push data from an dot net core API to a WPF application whenever new data is pushed to the API? Is this a good way to go about it? Any information, suggestions, Or relevant technologies/frameworks/native C# tools used for this purpose would be greatly appreciated.
Upvotes: 1
Views: 152
Reputation: 152
It looks like you need Web Sockets.
Web Sockets, as apposed to HTTP, create a persistent connection between the client and host, allowing the host to push data to the client in real time.
I recommend SignalR as an easy to use Web Socket framework, it can be easily added to a .NET Core app.
A great example of SignalR can be found on the Microsoft EShopOnContainers repo in the Ordering System.
The use a message queue between the main API and the SignalrHub, however you could easily combine the two for a simple application.
Upvotes: 2