Arduino: LCD + hezetasun/tenperatura sensorie

LCD: YwRobot LCM1602

LCD YwRobot LCM1602

DHT22 hezetasun/tenperatura sensorie:
DHT22

Hamen dana montata:
Arduino LCD + sensoreak

Oin kodigue:

Nire kasuen DHT22 da, DHT21 edo DHT11 badakozun, // kendu zeurieri eta imiñi bestieri:

...
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301
...

Oin bai kodigue :D

#include  // 
#include  // 
#include  // 

LiquidCrystal_I2C lcd(0x27, 516,2);
 
#define DHTPIN 2

#define DHTTYPE DHT22
 
DHT dht(DHTPIN, DHTTYPE);
 
void setup()
{
  lcd.init(); 
  lcd.backlight();
  dht.begin();
  Serial.begin(9600);
}
 
void loop()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature();
 
  if (isnan(t) || isnan(h))
  {
    lcd.clear();
    lcd.setCursor (0,0);
    lcd.print("Failed to read from DHT");
  }
  else
  {
    lcd.clear();
    lcd.setCursor (0,0);
    lcd.print("Hez:");
    lcd.print(h);
    Serial.print("Hezetasune:");
    Serial.print(h);
    Serial.println("");
    lcd.setCursor (0,1);
    lcd.print("Tenp:");
    lcd.print(t);
    Serial.print("Tenperaturie:");
    Serial.print(t);    
    Serial.println("");    
    delay(5000);
  }
}

Hamen dakozuie libreridxek eta upin danak bateko ia @GaurDaBihar honegaz pozik lotzien badan:

https://github.com/ZiTAL/arduino

LCD_I2C_DHT ariketie da, baie libraries karpetie derrigorrezkue da martxan imintzeko

raspberry pi: raspbian wifidxe WPA-gaz eta teklatuen hizkuntzie

http://www.raspbian.org/static/common/raspbian_logo.png
Raspberry pi-ntzako raspbian gnu/linux distribuziñuen zelan egin:

Wifi imiñi WPA/WPA2 PSK enkriptaziño motiegaz:

su
aptitude install wpasupplicant
wpa_passphrase ZEURE_WIFIDXEN_IZENA ZEURE_WIFIDXEN_PASAHITZA > /etc/wpa.conf
nano /etc/wpa.conf

/etc/wpa.conf

network={
        ssid="etxeko_wifiya"
        #psk="pasahitza"
        psk=fb59fc5917d71041feb1603b895bffe4d08307b89c854fc20cd01a9ec13dd6b5
}

Sartungo’tzagu:

key_mgmt=WPA-PSK

eta lotuko lekide:

network={
        ssid="etxeko_wifiya"
        key_mgmt=WPA-PSK
        #psk="pasahitza"
        psk=fb59fc5917d71041feb1603b895bffe4d08307b89c854fc20cd01a9ec13dd6b5
}

Gorde eta oin:
/etc/network/interfaces hurrengue sartungo’tzagu

#...
auto wlan0
iface wlan0 inet dhcp
        wpa-conf /etc/wpa.config

Oin wifidxe aktibeteko:

ifup wlan0

Oin gure bazuien wifi gehidxau sartun:
/etc/wpa.conf-en

network={
...
}
network={
...
}
network={
...
}

Bueno arazuek okinjotezelez teklauen hizkuntziegaz, ze ez dosten itzen kasu puterik pez:

su
aptitude install console-data
nano /etc/rc.local

eta exit 0 baño lelau sartun:

loadkeys es

adibidez:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
#_IP=$(hostname -I) || true
#if [ "$_IP" ];
#       printf "My IP address is %s\n" "$_IP"
#fi

loadkeys es

exit 0

/etc/rc.local runlevel bakotzeko azkanatan imingo da martxan

ffmpeg/avconv erabilitze bideotutorialak egin

Beti erabili izen dot “recordmydesktop” aplikaziñue bideotutorialak grabateko, baie apur bet labur lotzien da eta denpora askokuek badizen askotan ez dau urteten ondo formatue gordekeran.

avconv:

avconv -f x11grab -s `xdpyinfo | grep 'dimensions:'|awk '{print $2}'` -r 25 -i :0.0 -same_quant output.ogv

ffmpeg:

ffmpeg -f x11grab -s `xdpyinfo | grep 'dimensions:'|awk '{print $2}'` -r 25 -i :0.0 -sameq output.ogv

Pantallen dakune grabateko:

-f x11grab ... -i :0.0

Resoluzioñue automatikoki hartzieko:

-s `xdpyinfo | grep 'dimensions:'|awk '{print $2}'`

25 frame segunduko grabateko:

-r 25 

Erakusten dun kalidade bardiñen gordeteko:

-same_quant/-sameq

Grabaten parateko:

Ctrl + C

http://www.commandlinefu.com/commands/view/148/capture-video-of-a-linux-desktop

Kinout keynote-ntzako mandue node.js -en

Kinout web ingurunerako keynote sistema bat da. tapquo -n biharrien dauen @soyjavi -k idatzi’tze “power point” motatako presentaziñeuk eitzeko, hamen dakozuie presetatu doten bideotutorialtxu bet ikusteko zelan ein mando bat atzera ta aurrera pasateko node.js erabilitze

Bididxue imiñi HD eta pantalle osorako, ostantzien ez dizelako ikusko sartzien dotazen komanduek eta kodiguek ;)

iptables: portue berzuzendu beste portu batera

Aupa aspaldikos (iñok leiduten badozten klaro). Ez dakitz ondo badauen “berzuzendu” berbie, baie euskalterm barridxegaz enai aklaraten eta bueno haulan lotzien da, ingelesezkue “redirect” berbie da. Zelan berzuzendu portu bet, beste batera, eta zetako?

Hasteko ta behin ia, gnu/linux-eko sistemako erabiltzaile “normalok” eztaku baimenik 1024 baño berauko porturen baten prosezurik imintzeko, orduen “root” moduen imili biher duz martxan, hori peligrosue al da ezan, haulan dala ta erabiltzaile normal moduen imiñi martxan prosezue eta gero iptables-egaz root moduen geuk gudun portora eruen, zelan?

su
iptables -t nat -I OUTPUT -p tcp -d 127.0.0.1 --dport 80 -j REDIRECT --to-ports 8888
iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8888
exit

1go erregeliek ezpadun imintzen ezin izangu gerue “localhost”-en probak egin.

Neure kaso konkretue, node-gaz okinjot aplikaziño bat martxan 8888 puertuen baie oin 80-gaz sartzien dast ;)

http://serverfault.com/questions/211536/iptables-port-redirect-not-working-for-localhost

jsonp: adibide sinple bat

Zer da jsonp? funtziño baten barruen json bat sartutie dominidxuen artien json-egaz biar eitzeko.

Zetako erabiltzen da? Ajax teknologidxek beran limitaziñuek dakoz, euretariko bat da, beste dominio batzukaz ezin zarala komunike, ta haurretarako erabiltzen da jsonp.

Zelan dabil? SCRIPT tag- bat sortu HTML-ien eta beste dominioko URL-ie bertan karga. URL honek ekarko dau ejekuteko dauen funtziñuen izena eta barruen json bat.

Adibide total sinple bat:

Geure HTML:

<!DOCTYPE html>
<html>
<head>
<title>jsonp example</title>
<script type="text/javascript">
window.onload = function()
{
  jsonp('http://bestedominiobat.com/jsonp.php');
};

function jsonp_callback(res)
{
  if(console)
    console.log(res);
}

function jsonp(url)
{
  var script = document.createElement('script');
  script.type = 'text/javascript';
  script.src = url;

  var head = document.getElementsByTagName('head')[0];
  head.appendChild(script);
}
</script>
</head>
<body>
</body>
</html>

http://bestedominiobat.com/jsonp.php

<?php
header("Content-Type: application/json");

$json = 'jsonp_callback(';
$json .= "{'result' : 'jsonp adibidie :)'}";
$json .= ');';

echo $json;
?>

ikusten dun moduen jsonp.php artxibuen: jsonp_callback(php)-an barruen sartun du json-a, orduen javascript-eko izen bardiñeko funtziñue ejekuteko da jsonp_callback(js).

node.js socket.io: socket bakotzeko sesiñue sortu: txat-an bigarren partie

Bueno ba hamen gabiltzez node.js eta socket.io-gaz barriro be, 1go partie ikusteko hamen linke:
http://zital.hackinbadakigu.net/?p=273
functions.js:

module.exports =
{
        in_array: function (needle, haystack, argStrict)
        {
                // Checks if the given value exists in the array
                //
                // version: 1109.2015
                // discuss at: http://phpjs.org/functions/in_array    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
                // +   improved by: vlado houba
                // +   input by: Billy
                // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
                // *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);    // *     returns 1: true
                // *     example 2: in_array('vlado', {0: 'Kevin', vlado: 'van', 1: 'Zonneveld'});
                // *     returns 2: false
                // *     example 3: in_array(1, ['1', '2', '3']);
                // *     returns 3: true    // *     example 3: in_array(1, ['1', '2', '3'], false);
                // *     returns 3: true
                // *     example 4: in_array(1, ['1', '2', '3'], true);
                // *     returns 4: false
                var key = '',        strict = !! argStrict;

                if (strict)
                {
                        for (key in haystack)
                        {
                                if (haystack[key] === needle)
                                {
                                        return true;
                                }
                        }
                }
                else
                {
                        for (key in haystack)
                        {
                                if (haystack[key] == needle)
                                {
                                        return true;
                                }
                        }
                }
                return false;
        }
};

server.js:

var functions = require('./functions');

var users_available = ['zital', 'hqh'];
var clients = {};

var server = require("socket.io").listen(6969);

server.sockets.on("connection", function(message)
{
        message.on("login", function(user)
        {
                if(functions.in_array(user, users_available))
                {
                        clients[message.id] = message;
                        clients[message.id].emit("isLogged");
                }
        });

        message.on("newMessage", function(data)
        {
                for(i in clients)
                        clients[i].emit("sendMessage", data);
        });

        message.on("logout", function()
        {
                var tmp = {};
                for(i in clients)
                {
                        if(i!=message.id)
                                tmp[i] = clients[i];
                }
                clients = tmp;
        });
});

index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Online chat</title>
<style>
body
{
    color: #fff;
    background: #333;
    font-family: "Helvetica", Arial;
    font-size: 14px;
    text-align: center;
}
.container
{
    background: #ccc;
    border-radius: 1em;
    box-shadow: 0px 5px 5px rgba(0,0,0,0.5);
    text-shadow: 5px 5px 5px rgba(0,0,0,0.5);
    margin: 1em auto;
    padding: 1em;
    width: 90%;
}

input
{
    display: block;
    font-size: 12px;
    margin: 1em auto;
    padding: 0.5em;
    width: 95%;
}

span
{
    display: block;
    font-size: 12px;
    margin: 1em auto;
    padding: 0.5em;
    width: 95%;
    text-align: left;
}
</style>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="socket.io.js"></script>
<script type="text/javascript">
<!--
// IP PUBLIKUE IMIÑI HAMEN
var websocket = io.connect("http://10.211.252.10:6969");

$(document).on('ready', function()
{
    $('#f_user').css('display', 'none');
    $('#f_message').css('display', 'none');
    $('#login').trigger('focus');

    websocket.on("isLogged", function()
    {        
        var login = $('#login');
        var user = login.val();

        $('#f_user > label').html('welcome: '+user);        

        $('#f_user').css('display', 'block');
        $('#f_message').css('display', 'block');
        $('#f_login').css('display', 'none');

        $('#message').trigger('focus');
    });

    websocket.on("sendMessage", function(data)
    {
        var chat = $('#zchat');
        var span = $('<span>'+data+'</span>');

        if (chat.children().length > 0 )
            chat.find(">:first-child").before(span);
        else
            chat.append(span);
    });

    $('#f_user').on('submit', function(e)
    {
        e.preventDefault();
        websocket.emit("logout", {});
        $('#f_user').css('display', 'none');
        $('#f_message').css('display', 'none');
        $('#f_login').css('display', 'block');
    });    

    $('#f_login').on('submit', function(e)
    {
        e.preventDefault();
        websocket.emit("login", $('#login').val());        
    });       

    $('#f_message').on('submit', function(e)
    {
        e.preventDefault();
        websocket.emit("newMessage", $('#message').val());
        $('#message').val('');
        $('#message').trigger('focus');
    });    
});
//-->
</script>
</head>
<body>
<div>
    <form id="f_user">
        <label></label>
        <input type="submit" value="logout" />
    </form>
    <form id="f_login">
        <label>login: </label>
        <input type="text" name="login" id="login" required />
        <input type="submit" />
    </form>
    <form id="f_message">
        <label>Message: </label>
        <input type="text" name="message" id="message" required />
        <input type="submit" />
    </form>
</div>
<div id="zchat">
</div>
</body>
</html>

socket.io.js:
http://pastebin.com/shJTm0JE

Oin martxan imintzeko:
server.js eta functions.js path bardiñen on bidiez, eta index.html eta socket.io.js bebai :)

node server.js

eta nabegadoretik index.html igiri

Non dau trukue? clients bariablien barruen sartutiegaz konektaten dizen erabiltzailiek, ta gero logout einkeran bertatik kendu.

php: reflection bidez metodo dinamikuek erabili

php-ntzako reflection API-dxe erabilitze, al’tzagu dinamismue emon geure programari, adibidez metodo dinamikueri deitsu, jakin barik ze motatako metodue dan, adibidez:

<?php
$class = 'a';
$method = 'b';
$params = array('d' => 'e');

// klasie existiten badan
if(class_exists($class)) 
{
        // metodue existiten badan
        if(method_exists($class, $method))
        {
                // reflection objetue sortu
                $reflection = new ReflectionMethod($class, $method);
                // metodue estatikue badan
                if($reflection->isStatic())
                {
                        $f = $class."::".$method;
                        $result = call_user_func($f, $params);
                }
                // metodue publikue badan leleu klasien instantzidxe sortu bi'de
                elseif($reflection->isPublic())
                {
                        $instance = new $class();
                        $result = $instance->$method($params);
                }
        }
}
if(isset($result))
{
        echo "<pre>";
        print_r($result);
        echo "</pre>";
}

class a
{
        public static function b($params = NULL)
        {
                return array('b' => $params);
        }
        public function c($params = NULL)
        {
                return array('c' => $params);
        }
}
?>

Erantzune:
<pre>Array                                                 
(                                                        
    [b] => Array                                                                                                                                                                   
        (                                                                                                                                                                          
            [d] => e                                                                                                      
        )                                                        
)                                                        
</pre>

Oin metodue ‘c’ imindxe:

$method = 'c';

Erantzune:

<pre>Array                                                 
(                                                        
    [c] => Array                                                                                                                                                                   
        (                                                                                                                                                                          
            [d] => e                                                                                                      
        )                                                        
)                                                        
</pre>

Gauze gidxau al diez egin, horretarako leidu RELECTION PHP API-dxe :)

ftp: binary vs ascii – checksum vs checksum

Zelan emon lei artxibo bardiñen checksum-ek ezberdin?

# binaidxo
md5sum -b config.xml 
263fe7751b96df9fc94fa4d6af2cfbb7 *config.xml
# texto moduen
md5sum -t config.xml 
263fe7751b96df9fc94fa4d6af2cfbb7 *config.xml
# binaidxo
md5sum -b config.xml.bak 
e96f4aa7b3a207778b904780db8d141f *config.xml.bak
# texto moduen
md5sum -t config.xml.bak 
e96f4aa7b3a207778b904780db8d141f *config.xml.bak

Sistema bakotzak beran “enter“-ak sortuten dauzelako kontuz okin biher da FTP bidez BINARY edo ASCII moduen gauzek botatiegaz:

file config.xml 
config.xml: UTF-8 Unicode text

file config.xml.bak 
config.xml.bak: UTF-8 Unicode text, with CRLF line terminators

Ikusten dan moduen ezta bardiñe FTP bidez ASCII moduen edo BINARY moduen botatie, holakorik ez pasateko bota beti BINARY moduen duderik dakozuieniko :)

debian: proxy anonimo bat sortu squid-egaz

Programaziño bidezko soluziñuek ibil nai topaten baie ez dot topa ezer dezenterik, orduen proxy bet montaten anime nai, batzuk lagunek dakuzelako internet zentsureten dauien herrialdietan, ta honegaz ba aukerie dakoie oingoz geuretzako askie dan internet erabiltzeko ;)

su
aptitude install squid apache2-utils
cd /etc/squid
mv squid.conf squid.conf.bak
nano squid.conf

squid.conf

# portue, baporana ez eh :D
http_port 8080
# autentifikaziño metodue eta ze artxibo erabili
auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/users
# "password" izeneko filtrue sortu esaten password-a eskatuteko
acl password proxy_auth REQUIRED
# "all" izeneko filtro bat sortu
acl all src 0.0.0.0/0.0.0.0
# "all" filtrueri esan user/passwd eskatuteko
http_access allow all password
#anonimotasune emoteko
forwarded_for off

Oin users artxibue sortu eta baimenak emon pasahitzek bertan gordeteko, horretarako apache-n htpasswd erabilku

htpasswd -c users usuaidxue
chmod 0644 users

/etc/init.d/squid restart
exit

Gero nabegadoran, adibidez firefox-en:

Edit -> Preferences -> Advanced -> Network

http://i.imgur.com/xiBM5.png

Ba betikulez IP aldatu ;)

Gero nabegakeran eskatukosku usuaidxue eta password-a, sartun ta abante!!!