Digitemp i zapis do mysql – instalacja dtgraph v0.4n

Opis budowy domowego termometra już był, dzis czas na opis konfiguracji jakiegoś “logera” tych informacji dla potomnych.

Opisze bardzo mało znane narzędzie  dtgraph v0.4n.

Do prawidłowego działania DTGraph wymaga oczywiście serwera WWW z obsługą PHP oraz serwer mysql oraz moduł PHP generujący JPG.

Ja jako demona www używam Apache w wersji 2.4.6, PHP w wersjii 5.5.6-1 oraz mysql 5.5.-33.1

apt-get update

apt-get install apache2 php5 mysql-server phpmyadmin libphp-jpgraph nano php-mdb2-driver-mysql php-pear

pear install MDB2-2.4.1

Teraz pobieramy ze źródeł dtgraph’a lub stąd -> http://pliki.gru.one.pl/01-2014/dtgraph-0.4n.tar.gz

Polecam pobrać sobie to na komputer na którym mamy jakies środowisko graficzne, będzie łatwiej.

Po wypakowaniu mamy strukturę katalogów, a nas interesuja dokładnie dwa katalogi czyli SQL i WWW.

Zawartośc katalogu WWW należy przesłać np poprzez SCP do katalogu /var/www na naszym serwerze.

Ja mam to w katalogu /var/www/dt

Zawartośc katalogu SQL – tam właśnie są tabele bazy danych które musimy wgrać do naszej bazy mysql.

Wchodzimy przeglądarką na nasz serwer http://<ip_serwera>/phpmyadmin logujemy się na konto root z uzyciem naszego hasła roota.

Teraz należy wyklikać sobie nową tabelę, moja ma nazwę temperatura, a do tej bazy importujemy wpisy zkatalogu DTGrapha

  • mysql_create_digitemp_metadata
  • mysql_create_digitemp
  • mysql_create_digitemp_alarms

Po zaimportowaniu tych 3-tabel praca w phpmyadmin jest skończona, teraz zostało skonfigurowanie reszty.

W  plikach DTGrapha znajduję sie conf.php

To już można wykonać w konsoli, czyli:

nano /var/www/dt/conf.php

Ukaże się nam plik konfiguracyjny:

<?php

/*
 * DTTemp Configuration File
 *
 * Structure loosely based on horde's components
 * (www.horde.org)
 */

/************** PHP config **************************/
// Ubuntu has E_NOTICE on - which causes problems sometimes.
// Also, Some MDB2 versions have deprecation
// Comment this out if you don't want this app to change your log
// level (applies to this app only)
ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_DEPRECATED);

/************** Database Properties *****************/
/****************************************************/
$conf['driver'] = 'sql';

$conf['sql']['phptype'] = 'mysql'; //typ bazy - pozostawiamy mysql

// What protocol will we use to connect to the database. The default
// is tcp, but if you wish to use UNIX sockets, change it to 'unix'.
$conf['sql']['protocol'] = 'tcp';

// If you are using UNIX sockets, you may need to specify the socket's
// location.
// $conf['sql']['socket'] = '/var/lib/mysql/mysql.sock';

// What port is the database server running on? Not required for all
// databases.
$conf['sql']['port'] = 3306; wskazujemy port, domyslnie opcja zakomentowana, wystarczy wpissac port standardowy to 3306 i odkomentowac linie

// What hostname is the database server running on, or what is the
// name of the system DSN to use?
$conf['sql']['hostspec'] = 'localhost';  //host bazy, zazwyczaj localhost

// What username do we authenticate to the database server as?
$conf['sql']['username'] = 'root';  // uzytkownik bazy
// What password do we authenticate to the database server with?
$conf['sql']['password'] = 'TWOJEHASLO';  // twoje haslo do konta

// What database name/tablespace are we using?
$conf['sql']['database'] = 'temperatura'; // nazwa stworzonej bazy danych przez Ciebie
//Main table name that digitemp_mysql.pl logs to
$conf['sql']['table'] = 'digitemp'; // te wartości pozostawiamy standardowe, jeśli nie zmianialiśmy naz tabeli
//Metadata table describing available sensors
$conf['sql']['table_meta'] = 'digitemp_metadata';
//Alarms table describing raised/old alarms
$conf['sql']['table_alarms'] = 'digitemp_alarms';
// What charset does the database use internally?
$conf['sql']['charset'] = 'iso-8859-1';
/********************* LOGGER **********************/
/****************************************************/
// This is for the script that will insert current
// readings into the database (PHP version).
// This is optional - it is needed only if you logger.php (on cron)
//$conf['digitemp_binary'] = '/usr/local/bin/digitemp';
$conf['digitemp_binary'] = '/usr/bin/digitemp_DS9097';
$conf['digitemp_config'] = '/root/.digitemprc';
/************** JPGraph Properties ******************/
/****************************************************/

//The dir path under which jpgraph.php and others can be found
//This may be relative or absolute (filesystem, not url)
$conf['jp_path'] = "/usr/share/jpgraph/";
/************** Graph Properties ********************/
/****************************************************/
$conf['graph'] = array(); //leave this line alone!

//The colors define the graph colors in reverse order
//The colors now come from the metadata table, but
//these are defaults for yet undescribed sensors
$conf['graph']['colors'] = array("black","gray","blue","red","green","yellow","magenta","purple");

//Background color of the graph image
$conf['graph']['bgcolor'] = '#F0F0FF';

//Graph size below (in pixels):
$conf['graph']['width'] = 800;
$conf['graph']['height'] = 600;
//$conf['graph']['width'] = 640;
//$conf['graph']['height'] = 480;

$conf['data'] = array(); //leave alone

/*** UNITS ****/
//Temp display units. Logging is assumed to be done in fahrenheit
//(As is suggested by the schema)
//Possible values are : "celsius", "fahrenheit"
//Note that changing this changes default,
//as well as changing the checkbox in the inteface to offer the
//other unit of measurement instead
//$conf['data']['units'] = 'fahrenheit';
$conf['data']['units'] = 'celsius';

/*** Precision ***/
//Number of digits to show after decimal point
//in stats, etc
$conf['data']['displayPrecision'] = 2;
/**** Initial ****/
//negative number of seconds to set start time to
//when the page is first visited
$conf['data']['defaultOffset'] = -3600 * 12; //3 hours ago

//same for alarm viewer
$conf['data']['alarmsDefaultOffset'] = -3600 * 24 * 60; //two months
// Safeties on incoming data:
$conf['data']['loggerValidTempMin'] = -80;
$conf['data']['loggerValidTempMax'] = 180;

// Default states of main interface checkboxes
$conf['data']['defaults'] = array(
 'show_stats' => true,
 'showLegend' => false,
 'showMargin' => false,
 'showMarks' => true,
 'showBands' => false,
 'showNegatives' => true,
 'datesAbsolute' => false,
 'showRepeats' => false,
 'showAll' => false,
 'showAlarms' => false,
 // toggleUnits is handled above: $conf['data']['units']
);
/**** THIN OUT ********/

/**
Thinning out data (dropping every Nth record from display)
This is basically an attempt to keep the graph drawing engine
From being overloaded with data (it will take forever)

There are two supported ways of skipping data
SQL and CODE (or AUTO - below)
Code will read all data for the requested timeframe, and then
decide what to skip. This results in more datatransfer from DB
but a much smoother distribution of points (read on)

SQL complicates the WHERE part of the select statement by restricting
time to being less than a calculated amount per hour,day,month, etc
this is crude but fast, and results in a dense bunch of points at the
beginning of each calculated interval.
This mode relies on the collectionInterval (below) and
will not be accurate if data for different sensors is
collected at different intervals, or if the data has
been selectively purged for any reason

A combination mode of AUTO allows the program to auto-detect when to use which
It uses the threshold below. Setting it to AUTO will result in a
count query ran every time, allowing to decide which method to use.
Count queries don't take a significant amount of time.

How will you know which mode it's using?
Well first of all, the graph will show
"Measurements shown 3233/9899" at the bottom, where 9899 is the total amount.
If that amount exceeds your threshold below, then it's using SQL.
The other indicator is that graph edges are particularly jagged in SQL mode.
**/
$conf['data']['thinOutMethod'] = "AUTO";

// ------ This is for AUTO thinOut method -----
//In AUTO mode (above), how many readings must
//there be to switch to SQL+CODE method of thinOut
//over just CODE mode for thinout
//For my XP1800+ CPU the value of 50000 seems good
//it slows down noticeably as you get closer to 100K
$conf['data']['thinOutAutoSQLThreshold'] = 50000;
// ------ This is for CODE/AUTO thinOut method -----
//First I need to know how often temperature is collected
//This is in minutes. This should agree with the interval
//in your cron schedule, if the itervals are uneven -
//put in average number of minutes
//This setting affects the SQL thin Out method
$conf['data']['collectionInterval'] = 5; //minutes

// -------- This is for all thinOut methods --------
//The algorithm will attempt to thin out the data to a point
//where the resulting datapoint count will be below this value
//Setting this to a reasonable value
//will keep rendering time reasonable
//This value is the total points for all sensors being displayed
//Note that having collectionInterval set correctly
//is imperative to correct guessing
$conf['data']['maxThinnedOutDataPoints'] = 1000;
/************** HTML Properties *********************/
/****************************************************/
$conf['html'] = array(); //no movo this lino

//Background color for main page
//as well as graph margin
//Tip: using simple colors (FF,DD, etc) usually
//yields exact color matches between graph margin
//and HTML background
$conf['html']['bgcolor'] = "#DDDDFF";

/***** FORM submission METHOD *****/
//set to GET to be able to bookmark the url
//with all the options,
//set to POST to have have a more aesthetically pleasing URL
//NOTE - cookies offer a more flexible way of
//remembering settings - see below
$conf['html']['formMethod'] = "POST";
/************ PREFS *************/
$conf['prefs'] = array();

//enable cookies for saving
//user preferences
$conf['prefs']['cookieenable'] = true;

//name for prefs cookie
$conf['prefs']['cookiename'] = 'dtgraphprefs';

//lifetime for prefs cookie, seconds
$conf['prefs']['duration'] = 31536000; //one year

/************** ALARMS ******************************/
/****************************************************/

// Enable alarm checking - if this is off, no new
// alarms will be raised or lowered
// Alarm checking is done via cron when you run
// alarms.php (or logger.php, see below)
$conf['alarms']['enable'] = true;

// Enable alarm checking whenever logger.php
// is run (depends on 'enable' also)
// If this is enabled, you only need one cron job -
// to invoke 'php logger.php'
// If you'd like to update alarm info less frequently,
// or if you're not using logger.php,
// you can set this to false and add 'php alarms.php' to cron
$conf['alarms']['onLogger'] = true;
//Enable alarms display support... this makes dtgraph
//check for active alarms every time the main page is hit
// but this doesn't actually raise alarms!
//This is the default value for the checkbox on the interface
$conf['alarms']['display'] = true;

//Notify whenever an alarm is raised
//This option applies to the admin
//script which gets run on a cron (optional)
$conf['alarms']['notify'] = true;
$conf['alarms']['notifyEmail'] = 'system-alert';

//format (for date() function) to show dates in html
$conf['alarms']['dateformat'] = 'm/d g:i A';

&nbsp;

/****************************************************/
$conf['version'] = '0.4n';

?>

Po krótce wyjaśniłem opcje które zmieniamy i ustawiamy.

U mnie do poprawnego odczytu czujników temperatury wymagały edycję w katalogu admin/logger.php

Zmiana polegała na zmianie linii:

$command = $conf['digitemp_binary'].' -q -a -o"%R %.2F" -c '.$conf['digitemp_config'];

na

$command = 'digitemp_DS9097 -q -a -o"%R %.2F" -c /root/.digitemprc';

Pozostało tylko dodać wykonywanie odczytu teperatury do crona, aby cyklicznie się odświerzała temperatura:

crontab -e

i doklejamy:

*/5 * * * * php -f /var/www/dt/admin/logger.php >> /dev/null 2>&1

Oczywiście musisz zmienić scieżkę do katalogu DTGrapha jeżeli masz inna.

Polecam również zabezpieczyć hasłem katalog /admin aby niepowołane osoby tam nie zaglądały.

Efekty pracy:

ss-dtgraph

 

 

 

 

 

 

 

 

Przykład działania ( już od około pól roku działa nieprzerwanie):

http://s.temperatura.gniezno.pl/dt

Server FTP na Debianie – vsftpd – Jako serwer publiczny i SSL (szyfrowany)

W internecie jest wiele opisów – jak zainsalować na serwerze z systemem Debian czy pochodnym, serwer FTP.
Wcześniej, używałęm ProFTPd, ale na Debianie Jessie, który obecnie jest w fazie testów, proces po prostu się wyłączał, a w logach było głucho..
Jako że czasem używam FTP na moim domowym serwerze, postanowiłem zainstalować vsftpd.

vsftpd (“Very Secure FTP Daemon”) na systemie Debian:

adduser ftp-pub --disabled-password -q
apt-get update; apt-get install vsftpd nano openssl

Serwer już jest na naszym serwerze zainstalowany, pozostaje go odpowiednio skonfigurować, pokaże jak zrobic to z obsługą szyfrowanych połączeń ( w przypadku połączenia użytkownika) a publiczny katalog bedzie bez szyfrowanego połączenia.

Taka konfiguracja działa u mnie, i jest jak najbardziej możliwa.

Generowanie certyfikatu:

openssl req -x509 -nodes -days 365 -newkey rsa:1024 \
-keyout /etc/ssl/private/vsftpd.pem \
-out /etc/ssl/private/vsftpd.pem 

Plik konfiguracyjny programu vsftpd:

nano /etc/vsftpd.conf

 

ftpd_banner="grucha.no-ip.pl / vsFTPd " ##nazwa twojego serwera

# Poziom z którego zostaje uruchomiony serwer
nopriv_user=ftp

# Uruchamianie serwera w trybie standalone, czyli osobnego procesu
listen=YES

# Okrelenie portu, na którym serwer ma nasłuchiwać
# (domylnym jest port 21, sugeruję tak zostawić)
listen_port=21

# Zabronienie na logowanie się użytkownikom anonimowym
anonymous_enable=YES

# Zezwolenie na logowanie się użytkownikom lokalnym
local_enable=YES

# Zezwolenie na zapis w katalogu użytkownika lokalnego
write_enable=YES

# Umask (w większoci serwerów używany jest 022)
local_umask=022

# limit szybkoci podawany jest w bajtach na sekundę,
# jeli jest ustawiony na 0 to brak jakiegokolwiek limitu
local_max_rate=0

# Włšczenie logowania
xferlog_enable=YES

# cieżka do pliku z logami
xferlog_file=/var/log/vsftpd.log

# Maksymalna liczba połšczonych użytkowników
max_clients=500

# Maksymalna liczba użytkowników mogących się połączyć z tego samego adresu IP
max_per_ip=20

# Banner, który będzie wyswietlany podczas logowania.
# W jego stworzeniu może być pomocny program app-misc/figlet.
banner_file=/etc/vsftpd.banner

# Ograniczenie użytkownikom do poruszania się jedynie w obrębie katalogu domowego
chroot_local_user=NO

# Katalog dla chroot'a
secure_chroot_dir=/home/

# Dodanie użytkowników, którzy mogš poruszać się poza katalogiem domowym
chroot_list_enable=NO

# Dodajemy użytkownika z przywilejami poruszania się poza katalogiem domowym np:
# echo "USER" >> /etc/chroot.list
chroot_list_file=/etc/chroot.list

# Katalog wyświetlany w przypadku logowania anonimowego
anon_root=/home/ftp-pub
no_anon_password=YES

# USTAWIENIA SSL!

rsa_cert_file=/etc/ssl/private/vsftpd.pem
rsa_private_key_file=/etc/ssl/private/vsftpd.pem
ssl_enable=YES
allow_anon_ssl=NO
force_local_data_ssl=YES
force_local_logins_ssl=YES
require_ssl_reuse=NO
ssl_ciphers=HIGH

Postarałem się wytłumaczyć mniej więcej co oznaczają poszczególne parametry ustawień vsftpd.
Na końcu konfiguracji znajdują się parametry ustawień funkcji SSL czyli protokołu FTPS

Teraz tworzyy powitalną wiadomość pokazującą się podczas nawiązywania połączenia:

touch /etc/vsftpd.banner; touch /etc/chroot.list
echo "Witam na moim serwerze FTP" >> /etc/vsftpd.banner

Teraz przeładowujemy konfiguracje:

/etc/init.d/vsftpd restart


I dodajemy do autostartu:

update-rc.d vsftpd defaults

Jak się połączyć z serwerem FTP posiadającym certyfikat SSL ?
TotalCommander: https://pomoc.home.pl/faq/300
FlashFXP (polecam): http://ishell.pl/laczenie-sie-z-serwerem-ftp–tlsssl.html

P.S
Jeżeli nie chcesz łączyć sie poprzez SSL, wystarczy że zmieniasz

ssl_enable=YES

na

ssl_enable=NO

W wyżej podanym pliku konfiguracyjnym.

TP-Link TL-WR1043ND v2 – i wsparcie OpenWRT AA (GargoylePL)

Nowy model TP-Link TL-WR1043ND v2 wspierany był tylko w galęzi TRUNK oprogramowania OpenWRT, jest to nowy model z stajni Chińskiego producenta tanich (i dobrych) routerów. Obecnie Administrator i współtwórca Polskiego oprogramowania Gargoyle, Cezary – przeportował wersję stabilna Open WRT AA na której właśnie bazuje Gargoyle PL.

Więcej informacji n.t portu: http://eko.one.pl/forum/viewtopic.php?pid=95474#p95474

Specyfikacja:

Procesor: Qualcomm Atheros QCA9558, taktowanym zegarem 720 MHz

Radio: zintegrowany układ radiowy pracujący w paśmie 2,4 GHz (3T3R, do 450 Mbps w trybie Speed Boost).

LAN: gigabitowy przełącznik Atheros AR8327N,

RAM/FLASH: 64 MB pamięci DDR2 (taktowanie 600 MHz) i 8 MB pamięci FLASH SPI NOR;

Oraz jedno gniazdo USB

(źródło – tech-blog.pl)

Test wydajności routera -> http://openrouter.info/forum/viewtopic.php?p=33084&sid=fb8e6ec8e7104992af125719208d8ed4#p33084

Galeria zdjęć routera -> http://galeria.tech-blog.pl/TP-Link_TL-WR1043ND_v2/

Pierwsze oprogramowanie GargoylePL na TP-Link TL-WR1043ND v2

Factory -> http://pliki.gru.one.pl/01-2014/gargoyle-1.5.11.6-ar71xx-tl-wr1043nd-v2-squashfs-factory.bin

Sysupgrade -> http://pliki.gru.one.pl/01-2014/gargoyle-1.5.11.6-ar71xx-tl-wr1043nd-v2-squashfs-sysupgrade.bin

Teraz mogło by paść pytanie.. dlaczego akurat opisałem ten router ? Już wyjaśniam; model TP-Link TL-WR1043ND v1 – czyli w białej obudowie – służył mi od bardzo dawna, co prawda teraz jego miejsce zajął już dwuzakresowy i mocniejszy WDR3600, to nadal mam wersję pierwszą, która nigdy mnie nie zawiodła a nowa wersja tego routera po prostu odświeża ten udany model. Opini jest wiele, a mimo to uważam że wersja pierwsza nadal nada się na router domowy, do łącza kablowego, 3G, czy WISP.

Poczytaj o tej serii w Wikipedii OpwnWRT -> http://wiki.openwrt.org/toh/tp-link/tl-wr1043nd znajdziesz tam miedzy innymi porównanie wersji.