Click here to Skip to main content
15,066,651 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
so I'm junior programmer and I'm pretty much having hard time to figure this out by myself.
I'm creating IoT web application based on MVC 5, with Code First database approach which does next things:
- Communicate with sensors over MQTT protocol (mosquitto broker)
- Shows values and some basic data from sensors on site
- Does value data import from sensor to database per user (or topic, cause every user has unique topic) every 5 hours
- Sends out data back to broker to activate some part of hardware after user specifies time between hardware activations and for long long hardware is gonna be active.

So the troubles I'm facing are:
1. How do I save data per user if user is logged out/ user is offline/ application is offline?
2. How do I create timer to do data saving every 5 hours?

Any ideas which could help me out are appreciated.
I'm trying to find out easiest way to solve this.

What I have tried:

I've seen that Quartz.NET, cron, HttpRuntime.Cache (with item expiration), Console Application, Web Service could help me out with this problem, but I dont quite understand their doing.

About data saving I also got informed about mosquitto persistence which saves data on broker till client connects, so I'm also wondering how good that approach is?
Updated 13-Jun-17 21:40pm
F-ES Sitecore 14-Jun-17 5:18am
MVC is the wrong technology to use. Websites are a request\response technology, meaning they "do things" when a client requests a url and once the url has finished having its response generated it goes back to doing nothing. Given you are gathering data from some kind of hardware that doesn't suit your needs unless you have something making constant requests to your site and those requests interrogate the hardware.

You're going to need something that is constantly running that can handle your needs so a Windows Service is probably the best solution for you. The service can handle all the MQTT stuff and updating databases etc and if you want that data visible via the web then you could have an MVC site that simply shows the relevant data from the database to the user, however the MVC site would take no part in the actual data gathering itself.
Faris Karcic 15-Jun-17 2:42am
Thank you very much for your response!
You have pointed me which way to go to, appreciate it!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900