简体   繁体   中英

Notify multiple clients on db update using Asp.net

I'm having trouble designing a system and need help.

I have a system which consists of:

Zigbee module
Sensor
Raspberry pi
Website
SMS Gateway

Connection between zigbee, sensor and raspberry pi is all sorted out.

There are multiple collections of the (zigbee, sensor raspberry pi) package and each shall be administrated on the website. Whenever the raspberry pi detects a breakin it should send some kind of notification which will be send out to pre-determined users that must receive an SMS with a link that gives them information about which raspberry pi reported the breakin and who the raspberry pi belongs to.

So far I have designed a website using asp.net mvc5 and it is running OK, you are able to create new raspberry pi's, assign them to houses and so on. So all the simple insert/delete/edit to the database is done.

I have used Web API to make the raspberry pi able to change data in the database, so whenever it checks if it can find the sensors that belongs to it, it will make a PUT which looks like this:

 public HttpResponseMessage Put([FromBody] ICollection<Sensor> changedSensors )
    {
        ICollection<Sensor> sensorsNotRecognized =  new Collection<Sensor>();
        if (_repo.ChangeSensors(changedSensors) && _repo.Save())
        {
            foreach (var sensor in changedSensors)
            {
                if (sensor.Recognized == false)
                    sensorsNotRecognized.Add(sensor);
            }
            if (sensorsNotRecognized.Count > 0)
            {
                //REACT (SOME SENSORS NOT RECOGNIZED)
                //TODO react


            }

             return Request.CreateResponse(HttpStatusCode.OK);

        }
           return Request.CreateResponse(HttpStatusCode.BadRequest, changedSensors);
    }

What I want now, is that if one of the sensors haven't been set to recognized I need to notify the user that belongs to the raspberry pi that made the database update.

I currently dont have any kind of membership system implemented and what I would like to know is: I have looked into SignalR, can that be used to notify the user? If so, how? Should I use asp.net membership system or implement my own?

git of the project is here: https://github.com/Niclassg/lenio

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM