Tinman thanks!
With the help of your post i've got it sorted out.
I've tried to make a tutorial/WikI
Maybe you can walk through it to check if everything is ok and then someone can make a wiki off it?
Install Max on rpi
Stop nginx webserver before you begin else apache will not start as it can't bind to port 80 (or change the port). Domoticz doesn't use nginx.
and prevent it restarting on reboot.
Install Java
Code: Select all
sudo apt-get install openjdk-7-jre-headless
Install Apache (Webserver), MySQL (Databaseserver), PhpMyAdmin and PHP.
Code: Select all
sudo apt-get install apache2 libapache2-mod-php5 zendframework php5-mysql mysql-server phpmyadmin php5-xcache
- Enter a password for the >>root<< user(needs to be confirmed)
- “apache2” Leave as selected and press enter
- “Configure the database for phpmyadmin with dbconfig-common?” press enter
- Enter a password for the database admin(Suggested to use the same password as for the root user)
- Enter a password for phpmyadmin(Needs to be confirmed)(Suggested to use the same password as for the root user)
Now test the webserver by entering your Rpi adress in a web browser(example
http://192.168.1.100), It should display a page that says “It Works”
Also test the PhpMyAdmin by entering your Rpi adress in a web browser(example
http://192.168.1.100/phpmyadmin/), It should display a page that says “Welcome to My PHP Admin”(In fact in my case it didn’t show up but was still able to proceed)
Now set the database for Maxstats(in this example I’ve used the password “raspberry” for the root user)
Code: Select all
sudo mysql --user=root --password=raspberry
CREATE USER 'maxstats'@'localhost';
SET PASSWORD FOR 'maxstats'@'localhost' = raspberry;
GRANT ALL ON maxstats.* TO 'maxstats'@'localhost' WITH GRANT OPTION;
CREATE DATABASE maxstats;
exit
Install Maxstats
Code: Select all
sudo mkdir /home/pi/maxstats
cd maxstats/
sudo wget https://github.com/ifavo/MaxStats/archive/master.zip
sudo unzip master.zip
sudo mv MaxStats-master/* ./
sudo rm master.zip MaxStats-master/ -R
sudo chown www-data:www-data /home/pi/maxstats/public/ -R
sudo nano /home/pi/maxstats/application/configs/application.ini
Change the following rules:
Code: Select all
#5: "UTC" => "Europe/Berlin"
#27: resources.db.params.username = "" => resources.db.params.username = "maxstats"
#28: resources.db.params.password = "" => resources.db.params.password = "raspberry"
#29: resources.db.params.dbname = "" => resources.db.params.dbname = "maxstats"
Save and exit using CTRL-O, Enter, CTRL-X
Code: Select all
sudo nano /etc/apache2/sites-available/default
Change the folowing rules:
Code: Select all
#4: DocumentRoot /var/www => DocumentRoot /home/pi/maxstats/public
#7: AllowOverride None => AllowOverride FileInfo
#9: <Directory /var/www/> => <Directory /home/pi/maxstats/public>
#10: Options Indexes FollowSymLinks MultiViews => Options Indexes FollowSymLinks
#11: AllowOverride None => AllowOverride Fileinfo
Your file should like this:
## <VirtualHost *:80>
## ServerAdmin webmaster@localhost
##
## DocumentRoot /home/pi/maxstats/public
## <Directory />
## Options FollowSymLinks
## AllowOverride FileInfo
## </Directory>
## <Directory /home/pi/maxstats/public>
## Options Indexes FollowSymLinks
## AllowOverride Fileinfo
## Order allow,deny
## allow from all
## </Directory>
## The rest wil stay the same!
Save and exit using CTRL-O, Enter, CTRL-X
Code: Select all
sudo a2enmod rewrite
sudo cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf.org
sudo nano /etc/apache2/apache2.conf
Move all the way to the bottom and add the following line:
Save and exit using CTRL-O, Enter, CTRL-X
Without these changes you will see the following
## [....] Restarting web server: apache2apache2: Could not reliably determine the server's
## fully qualified domain name, using 127.0.1.1 for ServerName
After the changes you will see:
##"[ ok ] Restarting web server: apache2 ... waiting ."
Now test the maxstats by entering your Rpi adress in a web browser(example
http://192.168.1.100), It should display a page that says “Cube(s)” and a button that says Load Cube
Now its time to install and configure Maxbuddy, we will use it without the userinterface and run it in the background(headless)
Code: Select all
sudo mkdir maxbuddy
cd home/pi/maxbuddy/
sudo wget http://download.maxbuddy.de/MAXBuddy-r9.16.2-linux.tar.gz
sudo tar xzvfp MAXBuddy-r9.16.2-linux.tar.gz
sudo rm MAXBuddy-r9.16.2-linux.tar.gz
Start Maxbuddy once, then it creates the files in the home directory of Pi
You will find you get a lot of errors, as the files it's trying to download are no longer on the Max site. You need to do this:
a) be sure to run ./headless.sh as it creates directories you need
b) navigate to home/pi/.maxbuddy/ext-libs and edit links-916.xml and replace the content with this
Code: Select all
<linklist>
<set checksums="https://dl.dropboxusercontent.com/u/57840205/Libs1-4-1/digest.txt">
<ext>https://dl.dropboxusercontent.com/u/57840205/Libs1-4-1/MaxEssentialsBackend-1.4.1.jar</ext>
<ext>https://dl.dropboxusercontent.com/u/57840205/Libs1-4-1/MaxLocalBackend-1.4.1.jar</ext>
</set>
</linklist>
Save it and make it read only
c) under the ext-libs directory create directories u/57840205/Libs1-4-1
d) manually download the three files in the xml above and put them in the Libs1-4-1 directory (it ought to do this itself on first run but fails checksum)
e) run ./headless.sh and it should find the cube
NOTE: Only one program can connect to the cube at any time. If you have maxbuddy already running on windows, be sure to exit properly as it will continue to run minimised by default. I wasted a fair amount of time trying to work out why Raspberry got stuck at [DEBUG]: controller connect... when running headless.sh
Add the MaxTrash script, create a file in home/pi/.maxbuddy/scripts called Domoticz.js and paste in the script and change the required parameters(ip/port)
Code: Select all
/*
Domoticz.js
2013-11-03
script for Max!Buddy
How to install: put it in the script-folder and enable the script in the Max!Buddy settings
Public Domain.
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
*/
function getInfo(info) {
info.name = 'Domoticz';
info.description = 'Connector for Domoticz';
info.interval = 30;
}
function run() {
var toString = function(text) {
return text + '';
};
var h2d = function(h) {
return parseInt(h,16);
};
var HID = '3', //Hardware ID of dummy in Domoticz
IP = '192.168.1.100', //IP address of Domoticz
Port = '8080', //Port of Domoticz
// for types please refer to http://sourceforge.net/p/domoticz/code/HEAD/tree/domoticz/main/RFXtrx.h
// for Maxbuddy API please refer to http://bugs.maxbuddy.de/projects/maxbuddy/wiki/Buddy_API
WMT_dtype1 = '80', WMT_subtype1 = '9', //WallMountedThermostat Domoticz types for current temperature (temperature , RUBiCSON)
HT_dtype1 = h2d('0x50'), HT_subtype1 = '9', //HeatingThermostat Domoticz types for current temperature (temperature , RUBiCSON)
HT_dtype2 = h2d('0x52'), HT_subtype2 = h2d('0xA'), //HeatingThermostat Domoticz types for current temperature (temperature , RUBiCSON)
SC_dtype1 = h2d('0x20'), SC_subtype1 = '01', //ShutterContact
einde;
var startTime = new Date().getTime(),
URL = java.net.URL,
IOUtils = org.apache.commons.io.IOUtils,
DataOutputStream = java.io.DataOutputStream,
JSON = {},
roomIDs = buddy.getRoomIDs(),
SerialNumber, DomoticzDid, Temperature, SetPointTemperature, Valve, WindowOpen;
var OpenUrl = function(did, dunit, dtype, dsubtype, nvalue, svalue, response) {
var URLString;
URLString = 'http://'+IP+':'+Port+ '/json.htm?type=command¶m=udevice&hid='+HID+'&did='+did+'&dunit='+dunit+'&dsubtype='+dsubtype+
'&dtype='+dtype+'&nvalue='+nvalue+'&svalue='+svalue;
debug( ' '+URLString);
var url = new URL( URLString),
outputStream,
out;
connection = url.openConnection();
connection.setRequestMethod('POST');
connection.setReadTimeout(5000);
connection.setDoOutput(true);
connection.setRequestProperty('Content-type', 'application/json');
try {
outputStream = connection.getOutputStream();
out = new DataOutputStream(outputStream);
out.writeBytes(response);
out.flush();
out.close();
connection.connect();
connection.getInputStream();
}
catch(err) {
debug(new Error('Could not connect to server: '));
debug(err);
}
};
debug('Start run()');
for(var i=0; i < roomIDs.length; i++) {
var room = buddy.getRoom(roomIDs[i]),
mode = buddy.getRoomMode(roomIDs[i]),
_devices = room.getDevices(),
devices = [];
debug('Room = '+room.getName());
debug('Mode = '+mode.getMode());
//debug('Param = '+mode.getParameters());
for(var j=0; j < _devices.size(); j++) {
var device = _devices.get(j),
state = device.getState();
debug(' Device = '+device.getName());
SerialNumber = device.getSerialNumber();
debug(' SerialNumber = '+SerialNumber);
debug('');
if(device.getDeviceType() == 'WallMountedThermostat') {
DomoticzDid = toString(h2d(SerialNumber.substring(3)));
Temperature = toString(state.getTemperature());
debug(' Temperature = '+Temperature);
OpenUrl(DomoticzDid, '1', WMT_dtype1, WMT_subtype1, '0',Temperature);
debug('');
}
if(device.getDeviceType() == 'HeatingThermostat') {
// chop off first 3 characters (e.g. JEQ or KEQ). Then convert to decimal because domoticz will do dec to hex conversion
// this way the ID in domoticz is the same as the SerialNumber
DomoticzDid = toString(h2d(SerialNumber.substring(3)));
Temperature = toString(state.getMeasuredTemperature());
debug(' Temperature = '+Temperature);
SetPointTemperature = toString(state.getSetPointTemperature());
SetPointTemperature = SetPointTemperature.substring(0, SetPointTemperature.indexOf(',')+2).replace(',','.');
debug(' SetPointTmp = '+SetPointTemperature);
Valve = toString(state.getValvePosition());
debug(' Valve = '+Valve);
OpenUrl(DomoticzDid, '1', HT_dtype1, HT_subtype1, '0', Temperature);
OpenUrl(DomoticzDid, '2', HT_dtype2, HT_subtype2, '0', SetPointTemperature+';'+Valve+';0'); // HumidityStatus = 0 ???
debug('');
}
if(device.getDeviceType() == 'ShutterContact') {
DomoticzDid = toString(SerialNumber.substring(3));
if (state.isWindowOpen() == true) {
WindowOpen = 2;
}
else {
WindowOpen = 0;
}
debug(' Window open = '+ WindowOpen);
OpenUrl(DomoticzDid, '1', SC_dtype1, SC_subtype1, WindowOpen, '');
}
}
}
}
When added check the maxbuddy setting’s and adjust it to the sample below with your own parameters
Code: Select all
#MAX!Buddy Settings File
#Wed May 14 13:44:54 CEST 2014
settings.version=1
connection.reconnect=55
script.enabled.Domoticz.js=true
connect.lastip=192.168.1.100
connect.lastport=62910
connection.disconnect=1
Now lets make Maxbuddy start @reboot/startup(NOTE: Do not use Sudo here!)
Move all the way to the bottom and add the following line:
Code: Select all
@reboot cd /home/pi/maxbuddy/ && screen -d -m -S max /home/pi/maxbuddy/headless.sh
Save and exit using CTRL-O, Enter, CTRL-X
Now restart the Rpi
Now in your domoticz devices tab the The valve and thermometer appear as RUBiCSON sub type in domoticz