I'm very new to ASP.NET, am starting a project and would like some advice on how to proceed:
The project goal is to have a host raspberry pi use ASP.NET to host a local webpage that performs current/live data monitoring (controlling outputs, reading inputs) on other raspberry pi's connected to the host over the network.
I suspect I'll need to make a separate client program for tracking the pi's data and then sending the data to the host via tcp (or udp?), but currently I'm trying to start small with the host program by having a list of objects to display Pi data with. So my first question is how and where do I initialize a global list and then display that list on a page?
I've tried adding a Global class as such:
using PinServer.Models;
namespace PinServer
{
public static class Globals
{
public static List<RaspberryPi> SeedData { get; set; }
}
}
And then ran this in Program.cs:
Globals.SeedData = new List<RaspberryPi>() {
new RaspberryPi(1, "Test1", 4, 5, 2),
new RaspberryPi(2, "Test2", 7, 5, 5),
new RaspberryPi(3, "Test3", 3, 4, 2)
};
And then ran this code on the main page I used from a tutorial. I'm sure I need to be doing something else than "@model IEnumerable<PinServer.Models.RaspberryPi>", but what?
The program crashes claiming "Model" is null.
@model IEnumerable<PinServer.Models.RaspberryPi>
<h1>Raspberry Pis</h1>
<table border="1">
<tr>
<th>@Html.DisplayNameFor(model => model.Id)</th>
<th>@Html.DisplayNameFor(model => model.Name)</th>
<th>@Html.DisplayNameFor(model => model.Pin1)</th>
<th>@Html.DisplayNameFor(model => model.Pin2)</th>
<th>@Html.DisplayNameFor(model => model.Pin3)</th>
</tr>
@if (Model != null)
{
@foreach (var item in Model) {
<tr>
<td>@Html.DisplayFor(modelItem => item.Id)</td>
<td>@Html.DisplayFor(modelItem => item.Name)</td>
<td>@Html.DisplayFor(modelItem => item.Pin1)</td>
<td>@Html.DisplayFor(modelItem => item.Pin2)</td>
<td>@Html.DisplayFor(modelItem => item.Pin3)</td>
</tr>
}
}
</table>
And my second question is how would I add and display data in real time from the pi's?
I'm assuming ASP.NET MVC would be useful, so I started a template project for that. Here's that template project: https://github.com/paul-lindberg/pin-server/
Here are some articles I've saved to learn from: TCP connection between raspberry pi's: https://www.hackster.io/arioobarzan/connect-raspberry-pi-and-pc-with-tcp-ip-using-csharp-a299ed
Basic GPIO access: https://wellsb.com/csharp/iot/raspberry-pi-gpio-csharp-led
Thank you!