Industriële fabricage
Industrieel internet der dingen | Industriële materialen | Onderhoud en reparatie van apparatuur | Industriële programmering |
home  MfgRobots >> Industriële fabricage >  >> Manufacturing Technology >> Productieproces

Home Smart Home

Componenten en benodigdheden

Raspberry Pi 2 Model B
Oranje PI zou ook voldoende zijn
× 1
Xbee
× 1
Arduino UNO
× 1

Apps en online services

Microsoft Azure

Over dit project

Inleiding

Laten we eens kijken wat we nodig hebben om een ​​smart home-systeem op te zetten met MediaTek Linkit. Aangezien er hier veel experts zijn om u te begeleiden bij de hardware-aansluiting om de sensorgegevens te lezen, zal ik me concentreren op het maken van api's en het opzetten van een ultralage kosten lokale server van $ 15 om al uw sensorgegevens vast te leggen. Optioneel log ik de gegevens in azure.

Instellen

De sensoren verzenden hun gegevens via radiosignalen met behulp van xbee of een goedkope transceiver naar de MediaTek LinkIt. De MediaTek-linkIt ontvangt alle onbewerkte sensorgegevens, verpakt deze in een json-object met behulp van de adruinojson-bibliotheek en doet een POST-verzoek naar de lokale server. De lokale server host vervolgens de nodejs-webtoepassing en ontvangt alle sensorgegevens als json-objecten.

De lokale server wordt gebruikt als pre-processor en voegt de utc-tijd en handtekening toe. Eventuele gegevensvalidatie, conversie en filtratie kunnen hier worden verwerkt. De lokale server logt alle gegevens in de cloudservice in ons geval Azure Storage-services. Als alternatief kan MediaTek linkIt de json-objecten rechtstreeks naar Azure Storage-services posten. Ik heb een lokale server opgezet om te bewijzen dat een pc van $ 15 even krachtig genoeg kan zijn om onze gegevens te verwerken. we kunnen onze gegevens loggen in elke no-sql db, zelfs op onze lokale server, waardoor de noodzaak voor externe cloudopslag volledig wordt geëlimineerd. Ik laat dit allemaal aan jullie over.

Demo

 

Voorwaarde

Ik neem aan dat je weet hoe je sensorgegevens moet lezen met behulp van sensoren en microcontrollers zoals arduino of mediaTek. Om de reikwijdte van dit project te beperken, ga ik ervan uit dat de sensorgegevens beschikbaar zijn voor MediaTek Link It. U kunt een low-cast radiotransceiver of Xbee gebruiken om de radiosignalen te verzenden en te ontvangen van sensoren die zijn aangesloten op een microcontoller zoals MediaTek. Beginners kunnen de MediaTek linkIt groove starterkit gebruiken om de externe omgevingsgegevens zoals temperatuur, vochtigheid, licht enz. te lezen.

Json Json Json

Json is de de facto standaard voor iot geworden en wordt op grote schaal toegepast. Dit gezegd hebbende, laten we beginnen met het modelleren van onze sensorgegevens. Het belangrijkste doel is om zoveel mogelijk gegevens vast te leggen en door te geven aan de server. De server kan al het zware werk doen, zoals analyse, gegevensconversie, machine learning enz. 

De 'gewenste' json-object is de gewenste status van de sensorgegevens. Wanneer we bijvoorbeeld de temperatuur registreren, betekent de gewenste waarde van 24 dat we de waarde naar de cloud moeten synchroniseren met de waarde van 24. Onze klanten, zoals web-app of mobiele app, worden naar deze waarde bijgewerkt.

Als we een lamp willen aandoen, zeggen we, de gewenste staat als aan. Het betekent dat het licht is ingeschakeld of zal worden ingeschakeld. Al onze clienttoepassingen gebruiken deze status om de wijzigingen voor de gebruiker weer te geven. Ik bedoel, het pictogram in onze web-app wordt in- of uitgeschakeld.

Dit is geen internationale standaard, ik heb dit zojuist bedacht. Gebruik dus gerust je eigen handige formaat.

Temperatuur

{ "deviceid" :"iot/myhome/livingroom/thermostaat""desired" :{ "temperature" :"24", "humidity":"80"}, "timeutc":"2015-11 -23T00:41:48.824Z", "singedBy" :"localserver"} 

Microfoon

{ "deviceid" :"iot/myhome/livingroom/mic""desired" :{"intensity" :"66"}, "timeutc":"2015-11-23T00:41:48.824Z" , "singedBy" :"localserver"} 

Afstand

{ "deviceid" :"iot/myhome/livingroom/obstacle""desired" :{"proximity" :"150"}, "timeutc":"2015-01-01", "singedBy" :"localserver"} 

PIR

{ "deviceid" :"iot/myhome/livingroom/pir""desired" :{"motion start" :"2500", "motion end" :"5345"}, "timeutc":"2015 -11-23T00:41:48.824Z", "singedBy" :"localserver"} 

GPS

{"deviceid" :"iot/mydevice/location""desired" :{"lat" :"25.5", "long" :"32.2"},"timeutc":"2015-11-23T00 :41:48.824Z","singedBy" :"localserver"} 

Vocht

{"deviceid" :"/iot/myhome/garden/moisture""desired" :{"moisture":"20"},"timeutc":"2015-11-23T00:41:48.824Z ","singedBy" :"localserver"} 

Gas

{"deviceid" :" /iot/myhome/kitchen/gas""desired" :{"leak":"No"},"timeutc":"2015-11-23T00:41:48.824Z ","singedBy" :"localserver"} 

Licht

{"deviceid" :" /iot/myhome/livingroom/light""desired" :{"intensity":"60"},"timeutc":"2015-11-23T00:41:48.824Z ","singedBy" :"localserver"} 

Of gebruik dit,

Woonkamer

{"deviceid" :"/iot/myhome/livingroom""desired" :{ "temperature" :"25",                       "humidity" :"80",                                            wind       "", ":"closed",                      "light":"80",                       "noise":"low"}} 

Slaapkamer

{"deviceid" :"/iot/myhome/bedroom""desired" :{ "temperature" :"24",                     "humidity" :"70",                           "window"     sluiten ":"closed",                     "light":"80",                     "ac":"aan"                    "noise":"low"}} 

MediaTek - Ontvanger 

Raadpleeg het ino-bestand dat bij de softwaresectie is gevoegd om de gegevens op de lokale server in te loggen. De sensorgegevens worden gesimuleerd, u kunt de werkelijke meting doorgeven aan het respectieve json-object

Lokale server

Lokale server voegt overhead toe, maar zal op veel manieren nuttig zijn. We kunnen gebruik maken van een lokale server als pre-processor voor out iot data. Gegevens kunnen worden gefilterd, voorzien van een tijdstempel en ondertekend

Een kleine pc en nodejs is een uitstekende keuze voor een lokale server. We kunnen elke kleine pc kiezen, zoals raspberry pi, odriod, banana pi, beagle bone enz. Ik heb oranje pi ($ 15) gekozen voor dit project.

Instellen

Raspberry pi 2 of Orange Pi met elke smaak van linux os die nodejs 5 ondersteunt. Ik heb oranje pi met arch linux gekozen voor arm7. Nodejs en npm geïnstalleerd. Download mijn iotapp van github en navigeer naar /your/local/path/iotapp en voer npm install uit. De standaard expressjs-app begint te luisteren op uw poort 3000.

Blader naar your-local-ip:3000 om te controleren of de standaard expressjs-weergave wordt weergegeven. Ik heb deze api's gemaakt om de sensorgegevens te posten

/iot/myhome/livingroom/thermostaat - Temperatuur api

/iot/myhome/livingroom/mic - Geluid api

/iot/myhome/livingroom/pir - Aanwezigheidssensor api

/iot/myhome/livingroom/distance - Afstandssensor api

/iot/mijnhuis/mijnapparaat/locatie - gps-tracker-api

/iot/myhome/garden/moisture - bodemvochtsensor api

/iot/myhome/kitchen/gas - gasleksensor api

/iot/myhome/livingroom/light - lichtsensor api

/iot/myhome/livingroom - andere api voor woonkamer

/iot/myhome/bedroom - andere api voor slaapkamer


Om de lokale server in te stellen. Kloon de broncode iotapp van mijn github. Wijzig de index.js om uw cloud-IP-adres of domeinnaam te plaatsen waar de aspnet5-toepassing wordt gehost in azure

Externe server

Het publiceren van gegevens naar de cloud is tegenwoordig populair geworden. We kunnen een abonnement kopen van iot-gegevens zoals amazon, azuurblauw, vonkplezier, pubnub, beginstatus en vele andere. Ik heb gekozen voor azuurblauw voor deze demo. Er kunnen data-analyse, datamining en machine learning-algoritmen worden ontwikkeld om onze gegevens te verwerken.

Download de iotwebapp van mijn github. Ik heb het gemaakt met behulp van Visual Studio 2015 gericht op asp.net5. Deze api's waren ingesteld om de iot-gegevens te posten. De api logt de iot in de azuurblauwe opslagtabellen

De parameter deviceid kan worden ingesteld om te bepalen of de sensorlocatie is.

Deze api's zijn ingesteld, 

api/iot/myhome/thermostat - asp.net5 web-api om alle thermostaatgegevens te loggen 

api/iot/myhome/microphone- asp.net5 web-api om alle microfoongegevens te loggen

api/iot/myhome/pir - asp.net5 web-api om alle pir-gegevens te loggen

api/iot/myhome/distance - asp.net5 web-api om alle gegevens van de afstandssensor te loggen

api/iot/myhome/device/location - asp.net5 web-api om de gps-gegevens te loggen

api/iot/myhome/moisture - asp.net5 web-api om de gegevens van de vochtsensor te loggen

api/iot/myhome/gas - asp.net5 web-api om de gassensorgegevens te loggen

api/iot/myhome/light - asp.net5 web-api om alle lichtsensorgegevens te loggen

api/iot/myhome/livingroom - asp.net5 web-api om alle woonkamerattributen/sensorgegevens te loggen. we kunnen deze ene api gebruiken om alle sensorwaarden te pushen.

api/iot/myhome/bedroom - hetzelfde als hierboven, ik heb er een gemaakt om de details van mijn slaapkamer te loggen 

Externe server instellen. Kloon de broncode iotwebapp van mijn github. Maak een azuurblauwe opbergtafel. Wijzig de IoTController.cs en plaats de naam en sleutel van uw Azure Storage Table-account. Gebruik deze domeinnaam of ip op de lokale server

Conclusie

Er zijn veel gebieden die in de code moeten worden aangepast. Voel je vrij om te wijzigen en laat het me weten als je geraakt wordt.

Code

  • MediaTekRx
  • nodejs - lokale server
  • ThermoStatController.cs
  • PIRController.cs
  • MoistureController.cs
  • LivingRoomController.cs
  • LightController.cs
  • GPSController.cs
  • GasController.cs
  • DistanceController.cs
  • BedRoomController.cs
MediaTekRxC/C++
Media Tek als ontvanger. Schets naar lokale gegevens naar lokale server
/* Webclient Deze schets maakt verbinding met een website met behulp van Wi-Fi-functionaliteit op het MediaTek LinkIt-platform. Wijzig de macro WIFI_AP, WIFI_PASSWORD, WIFI_AUTH en SITE_URL dienovereenkomstig. gemaakt op 13 juli 2010 door dlf (Metodo2 srl) gewijzigd op 31 mei 2012 door Tom Igoe gewijzigd op 20 aug 2014 door MediaTek Inc. */#include #include #include #include #define WIFI_AP "uw ap"#define WIFI_PASSWORD "uw wachtwoord"#define WIFI_AUTH LWIFI_WPA // kies uit LWIFI_OPEN, LWIFI_WPA of LWIFI_WEP.#define SITE_URL "uw ip" //uw nodejs of azure ip-adres domeinnaamLWiFiClient c;void setup(){ LWiFi.begin(); Serieel.begin(115200); // blijf het opnieuw proberen totdat u bent verbonden met AP Serial.println ("Verbinding maken met AP"); while (0 ==LWiFi.connect (WIFI_AP, LWiFiLoginInfo (WIFI_AUTH, WIFI_PASSWORD))) {vertraging (1000); } // blijf het opnieuw proberen totdat u bent verbonden met de website Serial.println ("Verbinding maken met de website"); while (0 ==c.connect(SITE_URL, 3000)) { Serial.println("Opnieuw verbinding maken met website"); vertraging (1000); }}boolean disconnectedMsg =false;void loop(){ // Zorg ervoor dat we verbonden zijn, en dump de reactie-inhoud naar Serial while (!c) { Serial.println("Server verbroken.."); // blijf het opnieuw proberen totdat u bent verbonden met de website Serial.println ("Verbinding maken met de website"); while (0 ==c.connect(SITE_URL, 3000)) { Serial.println("Opnieuw verbinding maken met website"); vertraging (1000); } } Serial.println ("Leestemperatuur.."); updateTemperatuur(); vertraging (3000); Serial.println("Geluid detecteren.."); updateSound(); vertraging (3000); Serial.println("Persoonsbeweging detecteren.."); updatePIR(); vertraging (3000); Serial.println("Hindernis detecteren.."); updateDistance(); vertraging (3000); Serial.println("Apparaatlocatie bijwerken.."); updateGPSTracker(); vertraging (3000); Serial.println("Berekenen van bodemvocht.."); updateVocht(); vertraging (3000); Serial.println("Gaslekkage detecteren.."); updateGasLeak(); vertraging (3000); Serial.println("Opname lichtintensiteit.."); updateLightIntensity(); vertraging (3000); updateLivingroomAttributes(); vertraging (3000); updateBedroomAttributes(); delay(3000);}void writeToConsole(){ // Zorg ervoor dat we verbonden zijn, en dump de reactie-inhoud naar Serial while (c) {int v =c.read(); if (v !=-1) { Serial.print((char)v); } } Serieel.println(); Serial.println ("Server verbroken.."); // blijf het opnieuw proberen totdat u bent verbonden met de website Serial.println ("Verbinding maken met de website"); while (0 ==c.connect(SITE_URL, 3000)) { Serial.println("Opnieuw verbinding maken met website"); vertraging (1000); } }nietig updatePIR(){ lange niet-ondertekende int s; DynamischeJsonBuffer jsonBuffer; JsonObject&root =jsonBuffer.createObject(); JsonObject&gewenst =root.createNestedObject ("gewenst"); root["deviceid"] ="/iot/mijnhuis/woonkamer/pir"; // neem aan dat de standaardeenheid ms gewenst is ["motionstart"] =String (willekeurig (0,1000)); gewenst["motionend"]=String(willekeurig(1000,10000)); String len =String (root.measureLength()); c.println("POST /iot/myhome/livingroom/pir HTTP/1.1"); c.println("Host:" SITE_URL); c.println("Inhoudstype:applicatie/json"); c.println("Cache-Control:geen cache"); c.print("Inhoudslengte:"); c.println(len); c.println("Verbinding:sluiten"); c.println(); root.printTo(c); root.printTo(Seriële); //logica om een ​​langzame serverreactie te detecteren en het verzoek opnieuw te plaatsen zonder te wachten op een dode reactie s =millis(); // wacht op serverreactie Serial.println ("wacht op HTTP-reactie:"); while (!c.available()) { delay(100); if((millis() - s> 3000)) { Serial.println(); Serial.println("Server reageert niet.."); pauze; } } Serial.println("Bellen schrijven naar console.."); schrijfToConsole(); }void updateDistance(){ lange niet-ondertekende int s; DynamischeJsonBuffer jsonBuffer; JsonObject&root =jsonBuffer.createObject(); JsonObject&gewenst =root.createNestedObject ("gewenst"); root["deviceid"] ="/iot/myhome/livingroom/distancesensor"; // neem aan dat de standaardeenheid cm gewenst is ["obstakel"]=String(random(50.450)); String len =String (root.measureLength()); c.println("POST /iot/mijnhuis/woonkamer/afstand HTTP/1.1"); c.println("Host:" SITE_URL); c.println("Inhoudstype:applicatie/json"); c.println("Cache-Control:geen cache"); c.print("Inhoudslengte:"); c.println(len); c.println("Verbinding:sluiten"); c.println(); root.printTo(c); root.printTo(Seriële); s =millis(); // wacht op serverreactie Serial.println ("wacht op HTTP-reactie:"); while (!c.available()) { delay(100); if((millis() - s> 3000)) { Serial.println(); Serial.println("Server reageert niet.."); pauze; } } Serial.println("Bellen schrijven naar console.."); schrijfToConsole(); }void updateGPSTracker(){ lange niet-ondertekende int s; DynamischeJsonBuffer jsonBuffer; JsonObject&root =jsonBuffer.createObject(); JsonObject&gewenst =root.createNestedObject ("gewenst"); root["deviceid"] ="/iot/mijnapparaat"; gewenst["lat"] =String(willekeurig(20,25)); gewenst["long"]=String(willekeurig(22,27)); String len =String (root.measureLength()); c.println("POST /iot/mijnapparaat/locatie HTTP/1.1"); c.println("Host:" SITE_URL); c.println("Inhoudstype:applicatie/json"); c.println("Cache-Control:geen cache"); c.print("Inhoudslengte:"); c.println(len); c.println("Verbinding:sluiten"); c.println(); root.printTo(c); root.printTo(Seriële); s =millis(); // wacht op serverreactie Serial.println ("wacht op HTTP-reactie:"); while (!c.available()) { delay(100); if((millis() - s> 3000)) { Serial.println(); Serial.println("Server reageert niet.."); pauze; } } Serial.println("Bellen schrijven naar console.."); writeToConsole();}void updateMoisture(){ lange niet-ondertekende int s; DynamischeJsonBuffer jsonBuffer; JsonObject&root =jsonBuffer.createObject(); JsonObject&gewenst =root.createNestedObject ("gewenst"); root["deviceid"] ="/iot/mijnhuis/tuin/vocht"; // neem aan dat de gewenste standaardeenheid ["vocht"] =String (willekeurig (40,60)); String len =String (root.measureLength()); c.println("POST /iot/mijnhuis/tuin/vocht HTTP/1.1"); c.println("Host:" SITE_URL); c.println("Inhoudstype:applicatie/json"); c.println("Cache-Control:geen cache"); c.print("Inhoudslengte:"); c.println(len); c.println("Verbinding:sluiten"); c.println(); root.printTo(c); root.printTo(Seriële); s =millis(); // wacht op serverreactie Serial.println ("wacht op HTTP-reactie:"); while (!c.available()) { delay(100); if((millis() - s> 3000)) { Serial.println(); Serial.println("Server reageert niet.."); pauze; } } Serial.println("Bellen schrijven naar console.."); schrijfToConsole(); }nietig updateGasLeak(){ DynamicJsonBuffer jsonBuffer; JsonObject&root =jsonBuffer.createObject(); JsonObject&gewenst =root.createNestedObject ("gewenst"); gewenst["lek"] ="nee"; root["deviceid"] ="/iot/mijnhuis/keuken/gas"; lange ongetekende int s; String len =String (root.measureLength()); c.println("POST /iot/myhome/kitchen/gas HTTP/1.1"); c.println("Host:" SITE_URL); c.println("Inhoudstype:applicatie/json"); c.println("Cache-Control:geen cache"); c.print("Inhoudslengte:"); c.println(len); c.println("Verbinding:sluiten"); c.println(); root.printTo(c); root.printTo(Seriële); s =millis(); // wacht op serverreactie Serial.println ("wacht op HTTP-reactie:"); while (!c.available()) { delay(100); if((millis() - s> 3000)) { Serial.println(); Serial.println("Server reageert niet.."); pauze; } } Serial.println("Bellen schrijven naar console.."); schrijfToConsole(); }nietig updateLightIntensity(){ DynamicJsonBuffer jsonBuffer; JsonObject&root =jsonBuffer.createObject(); JsonObject&gewenst =root.createNestedObject ("gewenst"); gewenst["intensiteit"] ="80"; root["deviceid"] ="/iot/mijnhuis/woonkamer/licht"; lange ongetekende int s; String len =String (root.measureLength()); c.println("POST /iot/myhome/livingroom/light HTTP/1.1"); c.println("Host:" SITE_URL); c.println("Inhoudstype:applicatie/json"); c.println("Cache-Control:geen cache"); c.print("Inhoudslengte:"); c.println(len); c.println("Verbinding:sluiten"); c.println(); root.printTo(c); root.printTo(Seriële); s =millis(); // wacht op serverreactie Serial.println ("wacht op HTTP-reactie:"); while (!c.available()) { delay(100); if((millis() - s> 3000)) { Serial.println(); Serial.println("Server reageert niet.."); pauze; } } Serial.println("Bellen schrijven naar console.."); schrijfToConsole(); }nietig updateLivingroomAttributes(){ DynamicJsonBuffer jsonBuffer; JsonObject&root =jsonBuffer.createObject(); root["deviceid"] ="/iot/mijnhuis/woonkamer"; JsonObject&gewenst =root.createNestedObject ("gewenst"); //Alternatieve api voor loggin woonkamer attributen allemaal tegelijk gewenst ["window"] ="open"; gewenst["deur"] ="gesloten"; gewenst["ac"] ="uit"; gewenst["temperatuur"] =String(willekeurig(24,28)); gewenst["vochtigheid"] =String(willekeurig(60,65)); lange ongetekende int s; String len =String (root.measureLength()); c.println("POST /iot/mijnhuis/woonkamer HTTP/1.1"); c.println("Host:" SITE_URL); c.println("Inhoudstype:applicatie/json"); c.println("Cache-Control:geen cache"); c.print("Inhoudslengte:"); c.println(len); c.println("Verbinding:sluiten"); c.println(); root.printTo(c); root.printTo(Seriële); s =millis(); // wacht op serverreactie Serial.println ("wacht op HTTP-reactie:"); while (!c.available()) { delay(100); if((millis() - s> 3000)) { Serial.println(); Serial.println("Server reageert niet.."); pauze; } } Serial.println("Bellen schrijven naar console.."); schrijfToConsole(); } void updateBedroomAttributes(){ DynamicJsonBuffer jsonBuffer; JsonObject&root =jsonBuffer.createObject(); root["deviceid"] ="/iot/mijnhuis/slaapkamer"; JsonObject&gewenst =root.createNestedObject ("gewenst"); //Alternatieve api voor loggin woonkamer attributen allemaal tegelijk gewenst ["window"] ="open"; gewenst["deur"] ="gesloten"; gewenst["ac"] ="uit"; gewenst["temperatuur"] =String(willekeurig(22,23)); gewenst["vochtigheid"] =String(willekeurig(75,80)); lange ongetekende int s; String len =String (root.measureLength()); c.println("POST /iot/mijnhuis/slaapkamer HTTP/1.1"); c.println("Host:" SITE_URL); c.println("Inhoudstype:applicatie/json"); c.println("Cache-Control:geen cache"); c.print("Inhoudslengte:"); c.println(len); c.println("Verbinding:sluiten"); c.println(); root.printTo(c); root.printTo(Seriële); s =millis(); // wacht op serverreactie Serial.println ("wacht op HTTP-reactie:"); while (!c.available()) { delay(100); if((millis() - s> 3000)) { Serial.println(); Serial.println("Server reageert niet.."); pauze; } } Serial.println("Bellen schrijven naar console.."); schrijfToConsole(); } void updateSound(){ lange niet-ondertekende int s; lange ongetekende int e; DynamischeJsonBuffer jsonBuffer; JsonObject&root =jsonBuffer.createObject(); JsonObject&gewenst =root.createNestedObject ("gewenst"); gewenst["intensiteit"] =String(willekeurig(40,80)); root["deviceid"] ="/iot/mijnhuis/woonkamer/mic"; root["timeutc"] =""; root["ondertekend door"]=""; String len =String (root.measureLength()); c.println("POST /iot/myhome/livingroom/mic HTTP/1.1"); c.println("Host:" SITE_URL); c.println("Inhoudstype:applicatie/json"); c.println("Cache-Control:geen cache"); c.print("Inhoudslengte:"); c.println(len); c.println("Verbinding:sluiten"); c.println(); root.printTo(c); root.printTo(Seriële); s =millis(); // wacht op serverreactie Serial.println ("wacht op HTTP-reactie:"); while (!c.available()) { delay(100); if((millis() - s> 3000)) { Serial.println(); Serial.println("Server reageert niet.."); pauze; } } Serial.println("Bellen schrijven naar console.."); writeToConsole();}void updateTemperature(){ lange niet-ondertekende int s; lange ongetekende int e; DynamischeJsonBuffer jsonBuffer; JsonObject&root =jsonBuffer.createObject(); JsonObject&gewenst =root.createNestedObject ("gewenst"); gewenst["temperatuur"] =String(random(20,40)); gewenst["vochtigheid"]=String(willekeurig(60,80)); root["deviceid"] ="/iot/mijnhuis/woonkamer/thermostaat"; root["timeutc"] =""; root["ondertekend door"]=""; String len =String (root.measureLength()); c.println("POST /iot/mijnhuis/woonkamer/thermostaat HTTP/1.1"); c.println("Host:" SITE_URL); c.println("Inhoudstype:applicatie/json"); c.println("Cache-Control:geen cache"); c.print("Inhoudslengte:"); c.println(len); c.println("Verbinding:sluiten"); c.println(); root.printTo(c); root.printTo(Seriële); s =millis(); // wacht op serverreactie Serial.println ("wacht op HTTP-reactie:"); while (!c.available()) { delay(100); if((millis() - s> 3000)) { Serial.println(); Serial.println("Server reageert niet.."); pauze; } } Serial.println("Bellen schrijven naar console.."); schrijfToConsole(); }
nodejs - lokale serverJavaScript
De index.js die de routes heeft om de gegevens van Media te ontvangen Tek
var express =required('express');var router =express.Router();var buf =required('buffer');var request =vereisen ("request");//vervang uw-ip-of-domeinnaam door uw werkelijke ip-adres of domeinnaam//example iot.azurewebsites.com//example yourdomainname.com//example 47.12.67.16// accepteren POST-verzoek op de homepagerouter.post('/iot/myhome/livingroom/thermostat', function (req, res) { var state =req.body; state.timeutc =new Date(); state.signedby ="orangepi"; console.log(state); var options ={ method:'POST', url:'http://your-ip-or-domain-name/api/iot/myhome/livingroom/thermostat', headers:{ 'cache -control':'no-cache', 'content-type':'application/json' }, body:state, json:true }; request(options, function (error, response, body) { if (error) throw new Error (error); console.log(body); }); res.send('Living room temperature recording');});// accept POST-verzoek microuter.post('/iot/myhome/livingroom/mic' , plezier ction (req, res) { var state =req.body; state.timeutc =nieuwe datum(); state.signedby ="orangepi"; console.log(staat); var options ={ methode:'POST', url:'http://uw-ip-of-domeinnaam/api/iot/myhome/livingroom/microphone', headers:{ 'cache-control':'no- cache', 'content-type':'application/json' }, body:state, json:true }; request(opties, function (error, response, body) { if (error) throw new Error(error); console.log(body);}); res.send('Luxe kamer geluidsintensiteit opgenomen');});// accept POST-verzoek pirrouter.post('/iot/myhome/livingroom/pir', function (req, res) { var state =req.body; state.timeutc =new Date(); state.signedby ="orangepi"; console.log(state); var options ={ method:'POST', url:'http://your-ip-or-domain-name /api/iot/myhome/livingroom/pir', headers:{ 'cache-control':'no-cache', 'content-type':'application/json' }, body:state, json:true }; verzoek (opties, functie (fout, reactie, hoofdtekst) { if (error) throw new Error(error); console.log(body); }); res.send('Huiskamer pir beweging opgenomen');});/ / accept POST-verzoek distancerouter.post('/iot/myhome/livingroom/distance', function (req, res) { var state =req.body; state.timeutc =new Date(); state.signedby ="orangepi"; console.log(state); var options ={ method:'POST', url:'http://your-ip-or-domain-name/api/iot/myhome/livingroom/distance', headers:{ 'cache -control':'no-cache', 'content-type':'application/json' }, body:state, js op:waar }; request(opties, function (error, response, body) { if (error) throw new Error(error); console.log(body);}); res.send('Huiskamerobstakel opgenomen');});// accepteer POST-verzoek gpsrouter.post('/iot/mydevice/location', function (req, res) { var state =req.body; state.timeutc =new Date(); state.signedby ="orangepi"; console.log(state); var options ={ method:'POST', url:'http://your-ip-or-domain-name/api/ iot/mydevice/location/gps', headers:{ 'cache-control':'no-cache', 'content-type':'application/json' }, body:state, json:true }; request(options, function (error, response, body) { if (error) throw new Error (error); console.log(body); }); res.send('apparaatlocatie opgenomen');});// accepteer POST-verzoek vochtrouter .post('/iot/myhome/garden/moisture', function (req, res) { var state =req.body; state.timeutc =new Date(); state.signedby ="orangepi"; console.log(state ); var options ={ method:'POST', url:'http://your-ip-or-domain-name/api/iot/myhome/garden/moisture', headers:{ 'cache-control':' no-cache', 'content-type':'application/json' }, body:state, json:true }; request(options, function (error, response, body) { if (error) throw new Error(error); console.log(body); }); res.send('Garden moisture level recorded');});// accept POST request gasrouter.post('/iot/myhome/kitchen/gas', function (req, res) { var state =req.body; state.timeutc =new Date(); state.signedby ="orangepi"; console.log(state); var options ={ method:'POST', url:'http://your-ip-or-domain-name/api/iot/myhome/kitchen/gas', headers:{ 'cache-control':'no-cache', 'content-type':'application/json' }, body:state, json:true }; request(options, function (error, response, body) { if (error) throw new Error(error); console.log(body); }); res.send('Gas leak information recorded');});// accept POST request lightrouter.post('/iot/myhome/livingroom/light', function (req, res) { var state =req.body; state.timeutc =new Date(); state.signedby ="orangepi"; console.log(state); var options ={ method:'POST', url:'http://your-ip-or-domain-name/api/iot/myhome/livingroom/light', headers:{ 'cache-control':'no-cache', 'content-type':'application/json' }, body:state, json:true }; request(optio ns, function (error, response, body) { if (error) throw new Error(error); console.log(body); }); res.send('Light intensity recorded');});// accept POST request livingroomrouter.post('/iot/myhome/livingroom', function (req, res) { var state =req.body; state.timeutc =new Date(); state.signedby ="orangepi"; console.log(state); var options ={ method:'POST', url:'http://your-ip-or-domain-name/api/iot/myhome/room/livingroom', headers:{ 'cache-control':'no-cache', 'content-type':'application/json' }, body:state, json:true }; request(options, function (error, response, body) { if (error) throw new Error(error); console.log(body); }); res.send('Livingroom attributes recorded');});// accept POST request bedroomrouter.post('/iot/myhome/bedroom', function (req, res) { var state =req.body; state.timeutc =new Date(); state.signedby ="orangepi"; console.log(state); var options ={ method:'POST', url:'http://your-ip-or-domain-name/api/iot/myhome/room/bedroom', headers:{ 'cache-control':'no-cache', 'content-type':'application/json' }, body:state, json:true }; request(options, fu nction (error, response, body) { if (error) throw new Error(error); console.log(body); }); res.send('Bedroom attributes recorded');});// accept PUT request at /userrouter.put('/user', function (req, res) { res.send('Got a PUT request at /user');});// accept DELETE request at /user//router.delete('/user', function (req, res) {// res.send('Got a DELETE request at /user');//});/* GET home page. */router.get('/', function(req, res, next) { res.render('index', { title:'Express' });});module.exports =router;
ThermoStatController.csC#
api to log temperature data to the cloud
using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using Microsoft.AspNet.Mvc;using Newtonsoft.Json;using Microsoft.WindowsAzure.Storage;using Microsoft.WindowsAzure.Storage.Auth;using Microsoft.WindowsAzure.Storage.Table;// For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860namespace iotwebapp.Controllers{ [Route("api/iot/myhome/livingroom/[Controller]")] public class ThermoStatController :IoTController { // GET:// public IActionResult Index() { return View(); } [HttpPost] public IActionResult Post([FromBody]IotTemperature iotTemperature) { // Create the table client. CloudTableClient tableClient =storageAccount.CreateCloudTableClient(); // Create the CloudTable object that represents the "people" table. CloudTable table =tableClient.GetTableReference("iot"); iotTemperature.PartitionKey ="thermostat"; iotTemperature.RowKey =Guid.NewGuid().ToString(); // Create the TableOperation object that inserts the customer entity. TableOperation insertOperation =TableOperation.Insert(iotTemperature); // Execute the insert operation. table.Execute(insertOperation); return Ok("Temperature data logged to azure cloud.."); } } public class IotTemperature :TableEntity { public string deviceid { get; set; } public string timeutc { get; set; } public string signedby { get; set; } public string state { get { return JsonConvert.SerializeObject(this.desired); } set {; } } public Desired desired { get; set; } public class Desired { public string temperature { get; set; } public string humidity { get; set; } } }}
PIRController.csC#
api to log presence sensor data to azure
using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using Microsoft.AspNet.Mvc;using Microsoft.WindowsAzure.Storage.Table;using Newtonsoft.Json;// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860namespace iotwebapp.Controllers{ [Route("api/iot/myhome/livingroom/[Controller]")] public class PIRController :IoTController { [HttpPost] public IActionResult Post([FromBody]IotPIR iotPIR) { // Create the table client. CloudTableClient tableClient =storageAccount.CreateCloudTableClient(); // Create the CloudTable object that represents the "people" table. CloudTable table =tableClient.GetTableReference("iot"); iotPIR.PartitionKey ="pir"; iotPIR.RowKey =Guid.NewGuid().ToString(); // Create the TableOperation object that inserts the customer entity. TableOperation insertOperation =TableOperation.Insert(iotPIR); // Execute the insert operation. table.Execute(insertOperation); return Ok("PIR data logged to azure cloud.."); } } public class IotPIR :TableEntity { public string deviceid { get; set; } public string timeutc { get; set; } public string signedby { get; set; } public string state { get { return JsonConvert.SerializeObject(this.desired); } set {; } } public Desired desired { get; set; } public class Desired { public string motionstart { get; set; } public string motionend { get; set; } } }}
MoistureController.csC#
api to log soil moisture data to azure
using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using Microsoft.AspNet.Mvc;using Microsoft.WindowsAzure.Storage.Table;using Newtonsoft.Json;// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860namespace iotwebapp.Controllers{ [Route("api/iot/myhome/garden/[Controller]")] public class MoistureController :IoTController { [HttpPost] public IActionResult Post([FromBody]IotMoisture iotMoisture) { // Create the table client. CloudTableClient tableClient =storageAccount.CreateCloudTableClient(); // Create the CloudTable object that represents the "people" table. CloudTable table =tableClient.GetTableReference("iot"); iotMoisture.PartitionKey ="moisture"; iotMoisture.RowKey =Guid.NewGuid().ToString(); // Create the TableOperation object that inserts the customer entity. TableOperation insertOperation =TableOperation.Insert(iotMoisture); // Execute the insert operation. table.Execute(insertOperation); return Ok("Moisture data logged to azure cloud.."); } } public class IotMoisture :TableEntity { public string deviceid { get; set; } public string timeutc { get; set; } public string signedby { get; set; } public string state { get { return JsonConvert.SerializeObject(this.desired); } set {; } } public Desired desired { get; set; } public class Desired { public string moisture { get; set; } } }}
LivingRoomController.csC#
api to log all living room sensor data to azure
using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using Microsoft.AspNet.Mvc;using Microsoft.WindowsAzure.Storage.Table;using Newtonsoft.Json;// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860namespace iotwebapp.Controllers{ [Route("api/iot/myhome/room/[controller]")] public class LivingRoomController :IoTController { [HttpPost] public IActionResult Post([FromBody]IotLivingRoom iotLivingRoom) { // Create the table client. CloudTableClient tableClient =storageAccount.CreateCloudTableClient(); // Create the CloudTable object that represents the "people" table. CloudTable table =tableClient.GetTableReference("iot"); iotLivingRoom.PartitionKey ="livingroom"; iotLivingRoom.RowKey =Guid.NewGuid().ToString(); // Create the TableOperation object that inserts the customer entity. TableOperation insertOperation =TableOperation.Insert(iotLivingRoom); // Execute the insert operation. table.Execute(insertOperation); return Ok("Living room attributes logged to azure cloud.."); } } public class IotLivingRoom :TableEntity { public string deviceid { get; set; } public string timeutc { get; set; } public string signedby { get; set; } public string state { get { return JsonConvert.SerializeObject(this.desired); } set {; } } public Desired desired { get; set; } public class Desired { public string window { get; set; } public string door { get; set; } public string ac { get; set; } public string temperature { get; set; } public string humidity { get; set; } } }}
LightController.csC#
api to log light sensor data to azure
using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using Microsoft.AspNet.Mvc;using Microsoft.WindowsAzure.Storage.Table;using Newtonsoft.Json;// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860namespace iotwebapp.Controllers{ [Route("api/iot/myhome/livingroom/[Controller]")] public class LightController :IoTController { [HttpPost] public IActionResult Post([FromBody]IotLight iotLight) { // Create the table client. CloudTableClient tableClient =storageAccount.CreateCloudTableClient(); // Create the CloudTable object that represents the "people" table. CloudTable table =tableClient.GetTableReference("iot"); iotLight.PartitionKey ="light"; iotLight.RowKey =Guid.NewGuid().ToString(); // Create the TableOperation object that inserts the customer entity. TableOperation insertOperation =TableOperation.Insert(iotLight); // Execute the insert operation. table.Execute(insertOperation); return Ok("Light intensity logged to azure cloud.."); } } public class IotLight :TableEntity { public string deviceid { get; set; } public string timeutc { get; set; } public string signedby { get; set; } public string state { get { return JsonConvert.SerializeObject(this.desired); } set {; } } public Desired desired { get; set; } public class Desired { public string intensity { get; set; } } }}
GPSController.csC#
api to log gps data to azure
using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using Microsoft.AspNet.Mvc;using Microsoft.WindowsAzure.Storage.Table;using Newtonsoft.Json;// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860namespace iotwebapp.Controllers{ [Route("api/iot/mydevice/location/[Controller]")] public class GPSController :IoTController { [HttpPost] public IActionResult Post([FromBody]IotGPS iotGPS) { // Create the table client. CloudTableClient tableClient =storageAccount.CreateCloudTableClient(); // Create the CloudTable object that represents the "people" table. CloudTable table =tableClient.GetTableReference("iot"); iotGPS.PartitionKey ="gps"; iotGPS.RowKey =Guid.NewGuid().ToString(); // Create the TableOperation object that inserts the customer entity. TableOperation insertOperation =TableOperation.Insert(iotGPS); // Execute the insert operation. table.Execute(insertOperation); return Ok("GPS data logged to azure cloud.."); } } public class IotGPS :TableEntity { public string deviceid { get; set; } public string timeutc { get; set; } public string signedby { get; set; } public string state { get { return JsonConvert.SerializeObject(this.desired); } set {; } } public Desired desired { get; set; } public class Desired { public string lat { get; set; } [JsonProperty("long")] public string longitude { get; set; } } }}
GasController.csC#
api to log gas leakage data to azure
using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using Microsoft.AspNet.Mvc;using Microsoft.WindowsAzure.Storage.Table;using Newtonsoft.Json;// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860namespace iotwebapp.Controllers{ [Route("api/iot/myhome/kitchen/[Controller]")] public class GasController :IoTController { [HttpPost] public IActionResult Post([FromBody]IotGas iotGas) { // Create the table client. CloudTableClient tableClient =storageAccount.CreateCloudTableClient(); // Create the CloudTable object that represents the "people" table. CloudTable table =tableClient.GetTableReference("iot"); iotGas.PartitionKey ="gas"; iotGas.RowKey =Guid.NewGuid().ToString(); // Create the TableOperation object that inserts the customer entity. TableOperation insertOperation =TableOperation.Insert(iotGas); // Execute the insert operation. table.Execute(insertOperation); return Ok("Gas leak information logged to azure cloud.."); } } public class IotGas :TableEntity { public string deviceid { get; set; } public string timeutc { get; set; } public string signedby { get; set; } public string state { get { return JsonConvert.SerializeObject(this.desired); } set {; } } public Desired desired { get; set; } public class Desired { public string leak { get; set; } } }}
DistanceController.csC#
api to log ultrasonic distance sensor data to azure
using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using Microsoft.AspNet.Mvc;using Microsoft.WindowsAzure.Storage.Table;using Newtonsoft.Json;// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860namespace iotwebapp.Controllers{ [Route("api/iot/myhome/livingroom/[Controller]")] public class DistanceController :IoTController { [HttpPost] public IActionResult Post([FromBody]IotDistance iotDistance) { // Create the table client. CloudTableClient tableClient =storageAccount.CreateCloudTableClient(); // Create the CloudTable object that represents the "people" table. CloudTable table =tableClient.GetTableReference("iot"); iotDistance.PartitionKey ="distance"; iotDistance.RowKey =Guid.NewGuid().ToString(); // Create the TableOperation object that inserts the customer entity. TableOperation insertOperation =TableOperation.Insert(iotDistance); // Execute the insert operation. table.Execute(insertOperation); return Ok("Obstacle data logged to azure cloud.."); } } public class IotDistance :TableEntity { public string deviceid { get; set; } public string timeutc { get; set; } public string signedby { get; set; } public string state { get { return JsonConvert.SerializeObject(this.desired); } set {; } } public Desired desired { get; set; } public class Desired { public string obstacle { get; set; } } }}
BedRoomController.csC#
api to log all bedroom sensor data to azure
using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using Microsoft.AspNet.Mvc;using Microsoft.WindowsAzure.Storage.Table;using Newtonsoft.Json;// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860namespace iotwebapp.Controllers{ [Route("api/iot/myhome/room/[controller]")] public class BedRoomController :IoTController { [HttpPost] public IActionResult Post([FromBody]IotBedRoom iotBedRoom) { // Create the table client. CloudTableClient tableClient =storageAccount.CreateCloudTableClient(); // Create the CloudTable object that represents the "people" table. CloudTable table =tableClient.GetTableReference("iot"); iotBedRoom.PartitionKey ="bedroom"; iotBedRoom.RowKey =Guid.NewGuid().ToString(); // Create the TableOperation object that inserts the customer entity. TableOperation insertOperation =TableOperation.Insert(iotBedRoom); // Execute the insert operation. table.Execute(insertOperation); return Ok("Bed room attributes logged to azure cloud.."); } } public class IotBedRoom :TableEntity { public string deviceid { get; set; } public string timeutc { get; set; } public string signedby { get; set; } public string state { get { return JsonConvert.SerializeObject(this.desired); } set {; } } public Desired desired { get; set; } public class Desired { public string window { get; set; } public string door { get; set; } public string ac { get; set; } public string temperature { get; set; } public string humidity { get; set; } } }}
Media Tek Smart home - Source code for data logging
source code for nodejsapp, aspnet5 and mediatek receiver inohttps://github.com/syediddi/iot-mediatek-linkIt

Schema's

Transmit radio signal from arduino Transmit radio signal via Xbee from arduino without shield Transmit radio signals from arduino

Productieproces

  1. Slimme data:de volgende grens in het IoT
  2. 433MHz Smart Home Controller met Sensorflare en een RaspberryPi
  3. RASPBERRY PI HOME AUTOMATION
  4. Slimme barman
  5. Slimme ziekenhuizen van morgen hebben slimmere software nodig
  6. De kloof tussen slimme thuisvaardigheden
  7. De voordelen van interconnectiviteit op de werkplek
  8. Wees slim:de toekomst van je huis
  9. De droom van een slimme fabriek
  10. Smart home-connectiviteit:3 stappen om grote obstakels te overwinnen
  11. Smart Home-upgrades voor modern leven