Show Menu
Cheatography

IoT Cheat Sheet (DRAFT) by [deleted]

dsafdsfasddsafdsfasddsafdsfasddsafdsfasddsafdsfasddsafdsfasddsafdsfasddsafdsfasddsafdsfasddsafdsfasddsafdsfasddsafdsfasddsafdsfasd

This is a draft cheat sheet. It is a work in progress and is not finished yet.

3.2.2.5 - Install and Configure IoT Devices

Part 1. Setting up the Home Network

Step 1: Set up the wired network

Connect FastEt­hernet on Home Switch to Home Gateway using a coper straig­ht-­through cable.
Connect FastEt­hernet0 on PC -> FastEt­hernet on HomeSwitch
Set IPConfig of PC to DHCP

Step 2: Set up the wireless network

Home Gateway -> Config -> Internet -> select DHCP
Home Gateway -> Wireless -> change SSID to MyHome Gateway, auth to WPA2-PSK, use CiscoIoT as passphrase
Laptop -> Desktop -> PC Wireless -> Connect -> select MyHome­Gateway -> connect

Step 3: Connect the IoT devices to the network

Connect Coffee Pot to FastEt­hernet using copper straig­ht-­through cable
Coffee Pot -> Config -> FastEt­hernet0 -> select DHCP
Lamp/C­eiling Fan -> Config -> Wireless0 -> connect to MyHome­Gateway

Part 2. Intera­cting with IoT devices

Step 1: Acces the IoT devices locally

Click Alt + Lamp a few times, how many settings does the lamp have: 3
Alt + Lamp Switch: 2
Alt + Ceiling Fan: 3, Switch: 2
Alt + Coffee Pot: 2, Swtich: 2

Step 2: Configure the IoT devices for remote access

Lamp/C­eiling Fan/Coffee Pot -> Config -> IoE Server heading -> Remote server:
Server address: www.re­gis­ter.pka
Username: admin
Password: admin

-> connect

Step 3: Access the IoT devices remotely

Laptop­/Sm­art­phone -> Desktop -> Webbrowser -> www.re­gis­ter.pka -> login with admin:­admin
Devices can be controlle
 

Coffee Pot ins Internet hängen

Netcat starten:
nc -l 1234


Javascript Code beim Coffee Pot unter Advanced -> Progra­mming einfügen:
var state = 0;
var client = new RealTC­PCl­ient();
var coffee­status = ["Of­f","O­n"];

function setup() {
// 17 Zeilen ...
setSta­te(­state);
client.co­nne­ct(­"­ip", 1234);
}

// 10 Zeilen ...

function setSta­te(­new­State) {
// 10 Zeilen; client.send als letzte Zeile einfügen:

client.se­nd(­get­Nam­e()­+": "­+co­ffe­est­atu­s[s­tat­e]+­"­\n");
}

Netcat bekommt nun (nach Neustart und Cofee Pot Stop/S­tar­t/A­ltc­lick) Nachri­chten
 

Mozilla Webthings Gateway

Lubuntu in VM Winsta­lli­eren, Firefox in der VM starten, Mozilla Webgateway instal­lieren und starten, im Browser auf Config­seite gehen.

Codeex­ample

Dependency installieren: 
pip install webthing
from __future__ import division from webthing import (Action, Event, Property, SingleThing, Thing, Value,                      WebThingServer) import logging import time import uuid # Ein Event dass Überhitzung indiziert class OverheatedEvent(Event):     def __init__(self, thing, data):         Event.__init__(self, thing, 'overheated', data=data) # eine Action, welche die Lampe "faden" lässt class FadeAction(Action):     def __init__(self, thing, input_):         Action.__init__(self, uuid.uuid4().hex, thing, 'fade', input_=input_)     def perform_action(self):         time.sleep(self.input['duration'] / 1000)         self.thing.set_property('brightness', self.input['brightness'])         self.thing.add_event(OverheatedEvent(self.thing, 102)) def make_thing():     # lamp thing erstellen, kann ein/aus geschalten werden, hat verschiedene properties     thing = Thing(         'urn:dev:ops:my-lamp-1234',         'My Lamp',         ['OnOffSwitch', 'Light'],         'A web connected lamp'     )     thing.add_property(         Property(thing,                  'on',                  Value(True),                  metadata={                      '@type': 'OnOffProperty',                      'title': 'On/Off',                      'type': 'boolean',                      'description': 'Whether the lamp is turned on',                  }))     thing.add_property(         Property(thing,                  'brightness',                  Value(50),                  metadata={                      '@type': 'BrightnessProperty',                      'title': 'Brightness',                      'type': 'integer',                      'description': 'The level of light from 0-100',                      'minimum': 0,                      'maximum': 100,                      'unit': 'percent',                  }))     thing.add_available_action(         'fade',         {             'title': 'Fade',             'description': 'Fade the lamp to a given level',             'input': {                 'type': 'object',                 'required': [                     'brightness',                     'duration',                 ],                 'properties': {                     'brightness': {                         'type': 'integer',                         'minimum': 0,                         'maximum': 100,                         'unit': 'percent',                     },                     'duration': {                         'type': 'integer',                         'minimum': 1,                         'unit': 'milliseconds',                     },                 },             },         },         FadeAction)     thing.add_available_event(         'overheated',         {             'description':             'The lamp has exceeded its safe operating temperature',             'type': 'number',             'unit': 'degree celsius',         })     return thing def run_server():     # thing erstellen     thing = make_thing()     # webserver starten     # If adding more than one thing, use MultipleThings() with a name.     # In the single thing case, the thing's name will be broadcast.     server = WebThingServer(SingleThing(thing), port=8888)     try:         logging.info('starting the server')         server.start()     except KeyboardInterrupt:         logging.info('stopping the server')         server.stop()         logging.info('done') if __name__ == '__main__':     logging.basicConfig(         level=10,         format="%(asctime)s %(filename)s:%(lineno)s %(levelname)s %(message)s"     )     # server starten     run_server()