You can extend the functionality of SteelsquidKissOS in 3 ways
I recommend that you use the syncrionisation script. Dependencies on your development computerFor the synchronization script, SSH and GIT to works on Linux (preferably Debian) you need this packages installed. It should work on any other Linux distribution also. It probably works on Mac OS X also.
apt-get install bash gzip git openssh-client python2.7 python-paramiko Windows Use Putty for SSH: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html GIT: https://git-scm.com/download/win You do not need GIT, you can just download a zip instead if you want... Get the source codeOn your development computer. Change directory to where you want the source code (a project folder will be created) git clone https://github.com/steelsquid/steelsquid-kiss-os.git You can also download a zip here: Download this zip file and extractInstall Steelsquid KISS OS on the Raspberry PIChange directory to the project home on your development computer
SSH to Steelsquid Kiss OSExecute this on your development computer. ssh root@<ip_to_raspberry> Password: raspberry The synchronization script has a simple ssh client also so you do not need a separate SSH client... See "Automatic upload changes to Steelsquid Kiss OS" below. Development modeTo get some more log output enable development mode. Execute this on the Raspberry PI: steelsquid dev-on And reboot Expanded modeIf you execute steelsquid upgrade or steelsquid update-all, Steelsquid Kiss OS will bi upgraded. But if you are going to make changes, you will probably modify the following files. By executing: set-flag expanded the upgrade script will then not overwrite this files Systemd loggingThe logging on the system is set to a minimum. You should not need to to this, unless you get some strange errors. If you want to enable logging execute: steelsquid log-on And reboot Update Steelsquid Kiss OSYou can update Steelsuid Kiss OS to the newest version by executing the following. It can also be useful if you fucked up the system in some way. I recommend using steelsquid update-all NOTE! Do not turn off the device while the upgrade is in progress and the device must have internet connection.
Manual change Steelsquid Kiss OSIf you make changes to Steelsquid Kiss OS by edit on the device or upload manually you can implement it with this commands. But i recommend using the synchronize script (see next section).
Automatic upload changes to Steelsquid Kiss OSYou can start a program on the development machine that listen for changes on files and upload to Steelsquid Kiss OS automatically. This applies to the following files:
Move to the directory where you cloned from git (or extracted ZIP-file). Change IP number in the file config.txt to the ip number to Steelsquid Kiss OS. The 4 first row in the file contains this: IP PORT USER PASSWORD You can also add multiple server if you want to deploy the same to multiple servers. Use comma to separate like this: IP, IP, IP Port, user and password must be the same on all servers. More info on config.txt see Add custom files below. Then execute: ./steelsquid_synchronize.py Windows users: steelsquid_synchronize.exe When the program starts it will sync all files. You should see something like this: 2015-06-05 18:31:20 Load settings from steelsquid-kiss-os.sh 2015-06-05 18:31:20 Load settings from config.txt 2015-06-05 18:31:20 Connecting to: 192.168.0.102 ------------------------------------------------------------------------------ Listen for changes and commit to following server(s) 192.168.0.108 ------------------------------------------------------------------------------ H : help : Show this help Q : quit : This program will terminate T : test : Execute the /root/test.py script M : module : Reload the modules (/opt/steelsquid/python/modules/...) S : service : Start/Restart steelsquid service (implememt all changes) K : kill : Stop steelsquid service R : reboot : Reboot the remote machine L : list : List modules in modules/ (see if enabled or not) N : new : Create new module in modules/ (copy kiss_expand.py) A : annul : Delete a module in modules/ (You can not undo this!!!) E : enable : Enable a module in modules/ (will start on boot) D : disable : Disable a module in modules/ (will not start on boot) W : web : Create new HTML-file in web/ (copy template.html) V : delweb : Delete a HTML-file in web/ (You can not undo this!!!) ------------------------------------------------------------------------------ You can also send any other simple terminal line command (ls, pwd, mkdir...) But you can not use any commands that read input (nano, read, passwd) ------------------------------------------------------------------------------ 2015-06-05 18:31:21 SYNC: steelsquid-kiss-os.sh 2015-06-05 18:31:21 SYNC: steelsquid_boot.py 2015-06-05 18:31:21 SYNC: steelsquid_event.py ........... If you edit one of the monitored files it will be uploaded to Steelsquid Kiss OS automatically. A new row will show. example: 2014-12-07 19:29:50 SYNC: steelsquid_boot.py To exit the program type quit or q and press enter.
It is also a simple command line so you can type any other command like: ls, rm, rmdir... Most things you can use on a ordinary SSH terminal. But you can not use any commands that read input (nano, read, passwd) Messages and errors on the Steelsquid Kiss OS will also appear on the development machine. If you for example execute print Olle on Steelsquid KISS OS the text "Olle" will appear on the development machine. If you restart the service and get this message but then nothing else (no error or other log posts): 2015-01-04 23:51:03 FROM REMOTE DEVICE: Steelsquid service closed. If you shutdown the computer or restart the steelsquid service this is OK. If this is a error (nothing more happens) it is probably in steelsquid-boot.py You can enable logging for more info: steelsquid log-on Also sheck if steelsquid-boot proces is running: ps -ef|grep steelsquid-boot If not try: steelsquid-boot start And check for error... Then you can try this on the Raspberry Pi:
Also sheck if steelsquid-boot proces is running: ps -ef|grep steelsquid-boot If not try to start the steelsquid kiss daemon manually: steelsquid-boot start And check for error... Add custom filesIf you want to add your own files to Steelsquid Kiss OS and you want to edit them on you local computer. Create you file preferably under the source directory. Then edit config.txt and add the location to your file on the 6 row like this: Location on localsystem|Where do you want to put it on the Raspberry Example config.txt 192.168.0.194, 192.168.0.195 22 root raspberry myTextFile.txt | /opt/steelsquid/python/myTextFile.txt myBash.sh | /usr/bin/myBash.sh /home/steelsquid/onotherfile | /root/onotherfile Then execute: ./steelsquid_synchronize.py Windows users: steelsquid_synchronize.exe When you make changes to any file they will be uploaded automatically to the servers 192.168.0.194 and 192.168.0.195. You do not need to do this on .py files in the root or expand folder, they will be uploaded automatically. And files under web and img folder will also upload automatically. Make stuff execute on bootIf you want to implement new functionality I suggest you do it in the following files
The intention is that if you want to quickly add a feature do that in kiss_expand.py. But if you want to add several different features, create a new file in modules/ for every feature.
The files under modules/ can also listen to events and handle web requests. If the module have 2 methods enable and disable this will execute when the module is enabled /disabled. If the module have 6 different classes: SYSTEM, LOOP, EVENTS, WEB, SOCKET och GLOBAL you get a lot of extra stuff...
More information see the sections below... Enable and disable moduleThe two method enable and disable will execute when you use one of this commands.
The kiss_expand.py file will have example code for all this. The system will try to load settings with the same name as all variables in the class SETTINGS.
The variable value will also be used as default value if the paramater or list not is found When the system shutdown the value of the variable will also be saved to disk
To sum up: Variables in class SETTINGS that has value: Boolean, Array, Integer, Float, String will be persistent. The file under modules/ can subscribe to build-in events that will be executed by the system. The kiss_expand.py file will have example code for all this. It is much easier to understand if you look in that file...
If you create static methods in the LOOP class they will be executed in own threads. You can use any name you like for the method. Example:
Your own events (Class: EVENTS)Create staticmethods in the EVENTS class to listen for asynchronous events. The kiss_expand.py file will have example code for all this.
Built in webserver (Class: WEB)The built-in web server root is located at: /opt/steelsquid/web If you create a html file here you can reach it from the webserver. A good place to expand the web functionality is in the file expand.html The request can then be handled in any file under modules/ Create a class named: WEB(object) Staticmethod in this class will be executed by the webserver if module is enabled and the webserver is enabled The server will listen for http requests. If it is a GET it will return files and if it is a POST it executed commands. It is meant to be used as follows. Make a call from the browser (GET) and a static html page is returned back. This html page then make AJAX (POST) call to the server to retrieve or update data. The data requests sent to and from the server can just be a simple list of strings. Here is a short description how it works. In this example we create a request named wifi_status Create a staticmethod in the WEB class in kiss_expand.py to handle the request. It should have the same name as the request. And return a array with the data you want to send to the webclient. class SOCKET(object): def wifi_status(self, session_id, parameters): answer = steelsquid_utils.execute_system_command(['steelsquid-nm', 'system-status']) if answer[0] == 'None': return ["Not connected!", "---", "---", "---"] else: ip_wired = steelsquid_utils.network_ip_wired() ip_wifi = steelsquid_utils.network_ip_wifi() wan_ipp = steelsquid_utils.network_ip_wan() return [answer[0], ip_wired, ip_wifi, wan_ipp] Now to the HTML file For it to work you need this files (They are hardcoded into the server):
See expand.html for example Create a javascript function with the name on_<request-name> The functions parameter is the array from the request handler. Update the html in the page the way you like... function on_wifi_status(parameters){ $("#wifi_connected").html(paramaters[0]); $("#wifi_wired").html(paramaters[1]); $("#wifi_wifi").html(paramaters[2]); $("#wifi_wan").html(paramaters[3]); } To fire the request use this code. In another part of the javasscript you can fire: submitNoPW('wifi_status'); This will not show a please wait popup. Or fire from a button: <button id="download_enable" onclick="javascript:submitSync('wifi_status');">Get wifi</button> This will show a please wait popup There are many other ways to call too, see index.html for example. Also look at steelsquid.js for what else you can use. Built in Socket server (Class: SOCKET)A simple module that i use to sen async command to and from client/server. A request can be made from server to client or from client to server You can use this if you want to send simple commands between two devices.
The client will then try to connect to the server, if the server is restarted the client will continue to try. On the client, server or both add staticmethods to handle a request in the class GLOBAL(object): You need 3 methods with the command name + _request, _response, _error
Example use this in kiss_expand.py: Communication takes place in the following way (may also be the other way (client to server))
remote_address is the other sides address, example IP number This is what is send on the socket when a client send a request to the server:
Logic used from different places (Class: GLOBAL)Put global staticmethods in this class, methods you use from different part of the system. Maybe the same methods is used from the WEB, SOCKET or other part, then put that method here. It is not necessary to put it her, you can also put it directly in the module (but i think it is kind of nice to have it inside this class) Connect IO stuff/opt/steelsquid/flags/ Configuration flags /opt/steelsquid/lists/ Configuration lists /opt/steelsquid/parameters/ Configuration parameters /opt/steelsquid/pem/ HTTPS cerificate files Will be created when https is enabled /opt/steelsquid/web/ Web root /root Home folder (root user) /root/Media Link to /media /media USB disks will automatically be installed here. /root/test.py A python file to test stuff in... /opt/steelsquid/steelsquid-kiss-os.sh The steelsquid install and update script /etc/init.d/steelsquid Init script for /usr/bin/steelsquid-boot /etc/NetworkManager/dispatcher.d/99steelsquid.sh Fire network status /usr/bin/steelsquid -> /opt/steelsquid/steelsquid-kiss-os.sh The steelsquid script /opt/steelsquid/python Home for all python files /usr/bin/steelsquid-boot -> /opt/steelsquid/python/steelsquid_kiss_boot.py Python script that execute on boot and shutdown /opt/steelsquid/python/modules All python scrips in this folder will be imported (executed) on boot. Use this to inmplement your own stuff. /usr/local/lib/python2.7/dist-packages External python 2 libraries (Adafruit, RPi, picamera, wiringpi2) /usr/lib/python3/dist-packages External python 3 libraries (quick2wire) /opt/steelsquid/web/top_bar.html The black top bar that is on most pages /opt/steelsquid/web/download.html HTML-file for the download manager /opt/steelsquid/web/expand.html Use this to create your own stuff... /opt/steelsquid/web/file.html HTML-file for the filemanager /opt/steelsquid/web/index.html HTML-file for the web start page (settings) /opt/steelsquid/web/play.html HTML-file for the mediaplayer /opt/steelsquid/web/utils.html HTML-file for different utils (Camera streaming, alarm and rover) /opt/steelsquid/python/MCP23017.py Use the mcp23017 16-bit input/output port expander with interrupt output /opt/steelsquid/python/steelsquid_bluetooth_connection.py Bluetooth implementation of steelsquid_connection... /opt/steelsquid/python/steelsquid_boot.py This will execute when steelsquid-kiss-os starts /opt/steelsquid/python/steelsquid_connection.py A simple module that i use to sen async command to and from client/server. /opt/steelsquid/python/steelsquid_event.py Broadcast and subscribe to events, to use this you first must execute activate_event_handler(...) /opt/steelsquid/python/steelsquid_http_server.py This server will listen for http requests. /opt/steelsquid/python/steelsquid_i2c.py Use this to communicate with i2c devices. /opt/steelsquid/python/steelsquid_kiss_global.py Global stuff for steelsquid kiss os /opt/steelsquid/python/steelsquid_kiss_http_server.py Handles requests from index.html, download.html, file.html, play.html, utils.html /opt/steelsquid/python/steelsquid_kiss_socket_connection.py Controll steelsquid kiss os with simle socket commands /opt/steelsquid/python/steelsquid_lcd_hdd44780.py Print text on a HDD44780 compatible LCD from Raspberry Pi /opt/steelsquid/python/steelsquid_nm.py List and connect to wifi network using network manager /opt/steelsquid/python/steelsquid_oled_ssd1306.py Write text to a ssd1306 oled display /opt/steelsquid/python/steelsquid_omx.py Simple python interface for the omxplayer /opt/steelsquid/python/steelsquid_pi.py Some useful stuff for Raspberry Pi /opt/steelsquid/python/steelsquid_piio.py Mostly wrapper functions (hard coded adresses and pins) for my steelsquid PIIO board /opt/steelsquid/python/steelsquid_sabertooth.py A simple serial interface for Sabertooth motor controller. /opt/steelsquid/python/steelsquid_server.py A simple module that i use to listen for command and then execute stuff. /opt/steelsquid/python/steelsquid_socket_connection.py Socket implementation of steelsquid_connection... /opt/steelsquid/python/steelsquid_synchronize.py Automatic listen for changes abd commit changes to a nother system via ssh (install on remote system) /opt/steelsquid/python/steelsquid_trex.py Controll the Trex robot controller /opt/steelsquid/python/steelsquid_utils.py Some useful functions. /opt/steelsquid/python/modules/kiss_expand.py Use this file to implement you own stuff... /opt/steelsquid/python/modules/kiss_alarm.py This is functionality for my alarm. /opt/steelsquid/python/modules/kiss_rover.py Fuctionality for my rover controller /opt/steelsquid/python/modules/kiss_piio.py Fuctionality for my PIIO board |