DOMOTICA MAY MONTH Sander Claassen John Heesterbeek Ad van Berlo

Slides:



Advertisements
Similar presentations
Java Script Session1 INTRODUCTION.
Advertisements

PYTHON: LESSON 1 Catherine and Annie. WHAT IS PYTHON ANYWAY?  Python is a programming language.  But what’s a programming language?  It’s a language.
Python Programming Fundamentals
© 2011 Delmar, Cengage Learning Chapter 9 Collecting Data with Forms.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
Hans-Peter Plag November 6, 2014 Session 4 (Programming Languages) (Data Types and Variables) Expressions and Operators Flow Control.
Python – May 11 Briefing Course overview Introduction to the language Lab.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
Python uses boolean variables to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated.
Programming for GCSE 1.0 Beginning with Python T eaching L ondon C omputing Margaret Derrington KCL Easter 2014.
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
IST 210: PHP Basics IST 210: Organization of Data IST2101.
2007/11/16 Dinh Trong Thuy RTLab
Java Web Services Orca Knowledge Center – Web Service key concepts.
Class03 Introduction to Web Development (Hierarchy and the IDE)
Internet of Things.
Python Programming Unit -1.
Interfacing the Internet of a Trillion Things
Development Environment
Tiny http client and server
IE 8580 Module 4: DIY Monte Carlo Simulation
Student: Taariq Ghansar Supervisor: Prof Bagula
Node.Js Server Side Javascript
CS 330 Class 7 Comments on Exam Programming plan for today:
IoT Integration Patterns, REST, and CoAP
“Under the hood”: Angry Birds Maze
CS1022 Computer Programming & Principles
Building a conference attendee tracking system using DNN and MQTT
Content from Python Docs.
Topics Introduction Hardware and Software How Computers Store Data
CISC103 Web Development Basics: Web site:
Introduction to Python
z/Ware 2.0 Technical Overview
Introduction Python is an interpreted, object-oriented and high-level programming language, which is different from a compiled one like C/C++/Java. Its.
PYTHON: AN INTRODUCTION
Statement atoms The 'atomic' components of a statement are: delimiters (indents, semicolons, etc.); keywords (built into the language); identifiers (names.
Java programming lecture one
Lecture 1 Runtime environments.
Dave Eckhardt RPC Dave Eckhardt
HTTP: the hypertext transfer protocol
The Internet of Things (IoT)
Node.Js Server Side Javascript
1 Python Lab #1 Intro to Python Adriane Huber Debbie Bartlett.
Testing REST IPA using POSTMAN
CISC103 Web Development Basics: Web site:
DOMOTICA May MONTH Sander Claassen John Heesterbeek Ad van Berlo
Internet of Things.
Selection CIS 40 – Introduction to Programming in Python
Introduction to Python
DOMOTICA MAY MONTH Sander Claassen John Heesterbeek Ad van Berlo
Introduction to Python
Simple Socket Client Project 1.
Introduction to Algorithm Design
DOMOTICA MEI MAAND Sander Claassen John Heesterbeek Ad van Berlo
Enter the World of Industry 4.0 with UniStream MQTT
Python Jumpstart.
JavaScript.
Agile testing for web API with Postman
Channel Access Concepts
Lecture 1 Runtime environments.
Lecture 14: JSON and Web SERVICES
PHP Forms and Databases.
Selection Statements Chapter 3.
General Computer Science for Engineers CISC 106 Lecture 03
PHP-II.
EN Software Carpentry Python – A Crash Course Esoteric Sections Compiled Languages.
Intro to Programming (in JavaScript)
DIBBs Brown Dog BDFiddle
IoT Security and Privacy
Presentation transcript:

DOMOTICA MAY MONTH Sander Claassen John Heesterbeek Ad van Berlo Marco van Nieuwenhoven Hans Willemen MADspace community

Programma * Avond 1 - 2 mei Domoticz @ RasbperryPi * Avond 2 - 9 mei Sensors & actuators * Avond 3 - 16 mei Domotics bus-systems * Avond 4 - 23 mei JSON, MQTT & Python * Avond 5 - 30 mei Strut your stuff

Message type: JSON JavaScript Object Notation aka JSON 3 is an open-standard file/data format that uses human- readable text Json structures can contain strings, integers, booleans, arrays. Json structures can contain nested json structures. Json supports unicode text/characters: { "face": "\uD83D\uDE02" } or {“text”: u“TextAsUnicode“} https://www.domoticz.com/wiki/Presence_detection 3 3 3

Sending/Receiving JSON JSON-RPC: is a remote procedure call (RPC) protocol built on JSON. JSON-RPC lets a system send notifications (information to the server that does not require a response) and multiple calls to the server that can be answered out of order. Client packs the parameters in a message to the os to send to server. Server receives message and sends response. 4 4 4

Sending/Receiving JSON Domoticz json via http url: Get all devices of a certain type: http://192.168.1.1:8080/json.htm?type=devices&filter=all&used=true&order=Name http://192.168.1.1:8080/json.htm?type=devices&filter=temp&used=true&order=Name Domoticz json via python: http requests library: postdata = {'type':'devices', 'filter':'light','used':'true','order':'Name'} response = requests.get(url=self.apiUrl, params=postdata,headers=self.headers) print("Lights/Switches:\n{}".format(response.json)) 5 https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s 5 5

Network protocol: MQTT MQTT ia a ISO standard publish-subscribe-based messaging protocol. It works on top of the TCP/IP protocol. It is designed for "small code footprint" and limited network bandwidth. The publish-subscribe messaging pattern requires a message broker (Mosquitto). Multiple nodes/sensors can publish data to a broker Multiple services can subscribe to that data. For example Domoticz subsribes to a weather publisher. A remote wifi display subscribes to same weather. The Things Network (LoraWAN) uses MQTT to send/receive data. Node-Red (uses Blockly code) can interface to MQTT 6 6 6

Network protocol: MQTT Running MQTT broker on Raspberry: You'll need: Domoticz on Raspberry Pi Node.JS Node-RED A MQTT broker (Mosquitto) A few Node-RED example Flows 7 https://www.domoticz.com/wiki/MQTT 7 7

Network protocol: MQTT domoticz/in (to publish data to) domoticz/out (to subscribe to) Uses json compatible message format: { "idx" : 5, "name" : "Internal Temperature", "id" : "00080A", "unit" : 1 "dtype" : "Temp", "stype" : "TFA 30.3133", "nvalue" : 0, "svalue1" : "41.2", "Battery" : 100, "RSSI" : 12, } 8 8 8

Script/programming: Python Scripting language that is interpreted (and also compiled) on the fly. Next run it uses the compiled file (.pyc) to run faster (if no changes), that is why it also counts as high level programming language. Standalone scripts can interface with Domoticz through the json interface. Scripts called from Domoticz can import DomoticzEvents library to check for changed devices/variables. Python is much more compex to learn than Blockly Python is however more powerful. Python is a textual language, so saving a script is as simple as saving .py file. That being said, Domoticz Python Events are a different story since those seem to be hidden in a datbase. (cannot be found in the domoticz/scripts/python folder. 9 9 9

Quick introduction: Python Indentation: indentation is very important in python and must be consistent throughout the code. (don’t mix tabs with spaces) Methods/funtions: defined by “def” keyword Statements: if <condition>, elif <condition>, else (optional) for i in range(0,max_value+1), while Error catching: try, except statements. == (compare by value) vs “is” (compare by object reference) and, or and not: binary condition operators (equavalents to &&, || and !) Print() function and string .format(): print(“some string with var1={}\n and var2={}“.format(5,”C”)) 10 10 10

Quick introduction: Python 11 https://en.wikipedia.org/wiki/Python_(programming_language) 11 11

example: Python 12 https://github.com/vortexico/Domoticz-JSON (under construction) This script can also be run standalone from any machine in the network with python. 12 12 12

install: Python libraries On the commandline via ssh: $ python --version $ sudo apt-get install python-pip $ pip install requests $ pip install jsonrpclib (not needed yet) 13 13 13

assignment: Python With the script: check a sensor / alarm status and print the value on the command line Check if the temperature value is above X or if the sensor is triggered and switch lightswitch on/off Fun case 1: ESP sensor from workshop2 with temperature sensor. If temperature is above 22 degrees: switch on 433MHz switch (Fan) Fun case 2: depending on a temperature (from ESP or Darksky API) set the color of your light (MiLight, Hue, etc) Fun case 3: depending on rf moisture sensor level turn on a very slow water pump 14 14 14