Sunday 26 December 2010

Laptop Boot Image

I did an script in the past to take an picture every laptop boot and upload to server.

Here is an image with the thumbnails of almost 1500 images generated by Picasa.

Thursday 9 December 2010

Preparing Arduino Bug Zapper


Objectives:

Detect when a bug is killed
Send data to server



Testing ATmega 328 with Arduino bootloader



No PCB :(



Bug Zapper racket


Next steps:

Attach Electret Microphone [link]
Attach 315MHz Transmitter module [link]
Calibration
Add everything to racket inside





Saturday 20 November 2010

TMN A1 or Huawei U8230, switch applications, task list, recent applications

Use combination

off+menu

then choose "recent applications"

Friday 29 October 2010

Visualizing Facebook friends presence

I have set up a XMPP bot that connects to Facebook XMPP server, and monitors my friends login and logout operations.

For now i am only monitoring presence, but another's aspects could be easily derived and/or monitored :)

Chart values:

"1" means that the user has entered Facebook
"0" means that the user has logout

Chart lines:

"\" lines means a user session, user logins and a time after the user logs out
"/" lines like this, means the user is entering Facebook after being logged out
"V" the formed V's represent the user login and logout history


Note: this post only contains data from 15:30pm to 3:08 am, from first monitoring attempt.

Data from 15:30pm to 3:08 am



Drilling-down (zooming)


Platform raw chart page


The platform im using to upload sensor data is sawa (related to sensors), no need to create databases, just upload data and then render chart :)


Thursday 28 October 2010

SleekXMPP problems with DIGEST-MD5

I was trying to connect to facebook XMPP server using the sleekxmpp port that suports the SASL.

But was unable to connect....

1 2
    if not challenge['realm'] or not challenge['qop'] or not challenge['nonce']: KeyError: u'realm' 

Looking at protocol http://xmpp.org/rfcs/rfc3920.html#sasl the function handler_sasl_digest_md5_auth was not handling 2 essential steps:

"Step 7: Server sends another [BASE64] encoded challenge to client:"
and
"Step 8: Client responds to the challenge:"




Solution:
1
2
3
4
5
   self.sendPriorityRaw("""<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>%s</response>""" %base64.encodestring(response)[:-1])
self.digest_auth_started = True
else:
logging.warn("handler_sasl_digest_md5_auth called while digest_auth_started is True (has already begun)")
self.sendPriorityRaw("<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />")

Tuesday 19 October 2010

DHT11 Arduino with VirtualWire

By some reason when using VirtualWire library and using vw_setup(2000) caused the readings from humidity sensor to fail (dht11 start condition 1 not met). I looked at datasheet and changed a the times how the MCU starts to talk with the sensor.

The code is based from this post

Here is the the fixed code:

void InitDHT() {
 pinMode(TEMP_RH_PIN, OUTPUT);
 delay(1000);
 digitalWrite(TEMP_RH_PIN,HIGH);
}

void ReadDHT() {

 bGlobalErr=0;
 byte dht_in;
 byte i;
        
        // see datasheet to understand this
        pinMode(TEMP_RH_PIN, OUTPUT);
        digitalWrite(TEMP_RH_PIN,HIGH);
        
 digitalWrite(TEMP_RH_PIN,LOW);
 delay(18);

 digitalWrite(TEMP_RH_PIN,HIGH);
 delayMicroseconds(22);

 pinMode(TEMP_RH_PIN,INPUT);
 delayMicroseconds(5);

 dht_in=digitalRead(TEMP_RH_PIN);

 if(dht_in) {
  bGlobalErr=1;
  Serial.println("<dht11 start condition 1 not met");
  return;
 }
 
 delayMicroseconds(80);
 dht_in=digitalRead(TEMP_RH_PIN);

 if(!dht_in) {
  bGlobalErr=2;
  Serial.println("<dht11 start condition 2 not met");
  return;
 }
 delayMicroseconds(80);
 
        //now ready for data reception... pick up the 5 bytes coming from the sensor
 for (i=0; i<5; i++)
    dht_dat[i] = read_dht_dat();

 //Next: restore pin to output duties
 pinMode(TEMP_RH_PIN,OUTPUT);
 digitalWrite(TEMP_RH_PIN,HIGH);

 byte dht_check_sum = dht_dat[0]+dht_dat[1]+dht_dat[2]+dht_dat[3];

 /*Condition in following "if" says "if fifth byte from sensor
       not the same as the sum of the first four..."*/
 if(dht_dat[4]!= dht_check_sum) {
   bGlobalErr=3;
          Serial.println("DHT11 checksum error");   
 }

}


byte read_dht_dat() {
 //Collect 8 bits from datastream, return them interpreted
 //as a byte. I.e. if 0000.0101 is sent, return decimal 5.
 //Code expects the system to have recently entered the
 //dataline low condition at the start of every data bit's
 //transmission BEFORE this function is called.
 byte i = 0;
 byte result=0;
 for (i=0; i< 8; i++) {
  //We enter this during the first start bit (low for 50uS) of the byte
  //Next: wait until pin goes high
  while(digitalRead(TEMP_RH_PIN)==LOW);
  delayMicroseconds(30);
  if (digitalRead(TEMP_RH_PIN)==HIGH)//Was: if(PINC & _BV(dht_PIN))
  result |=(1<<(7-i));
  while (digitalRead(TEMP_RH_PIN)==HIGH);
  //Was: while((PINC & _BV(dht_PIN)));
 }
 //end of "for.."
 return result;
}

Thursday 14 October 2010

Arduino code to read lines from serial input

Here is short and useful example to read lines from serial port in Arduino.

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
void setup (){
  Serial.begin(9600);
  Serial.flush();
  digitalWrite (13, HIGH);      //turn on debugging LED
}

void loop (){

  int i=0;
  char commandbuffer[100];

  if(Serial.available()){
     delay(100);
     while( Serial.available() && i< 99) {
        commandbuffer[i++] = Serial.read();
     }
     commandbuffer[i++]='\0';
  }

  if(i>0)
     Serial.println((char*)commandbuffer);

}

Saturday 9 October 2010

python euromillion key generator with filters

From python, perl and ruby i selected python to start playing around (learn the language). I started with this nice tutorial "Learn Python in 10 minutes", and decided to port and old C program that generates all combinations of euromillions and then apply some filters.

The generator is for numbers only, it does not take into account the stars!!!

The solution is composed by two parts, the generator and the evaluator. The generator generates the combinations with the given filter list (e.g, python gnerator.py columns d_tens).
The evaluator, evaluates the success of the specified filters individually, and can evaluate all filters at same time.

As example the filter "first_number" rejects combinations with the first number more than 30

sh avaliator.sh first_number
################# first_numbers #####################
Running...
2044588 results 74172 rejected
~96.56160458452722063037%
###############################################

the report says that 15504 combinations was rejected and 97% of euromilions results are in the generated combinations file


However combining all filters (16 for now, and individually with 90% success), the success rate drops to 70% !!.

################# ALL #####################
Running...
1516959 results 601801 rejected
~70.77363896848137535817%
##########################################

Download here

Monday 8 February 2010

How to change openfire password or how to login in openfire







Im having some problems with SSL certificates, i reinstalled openfire to see if that would fix.
At login, it seems not be working the password i set in setup installation. Theres a way to change the password and resolve the issue of not be able to login.

1- Access openfire database
2- Select table ofUser
3- Edit admin row
4- Set encryptedPassword to NULL
5- Enter a temporary pass on plainPassword
6- Save and restart openfire server
7- Use temporary password to login (username is always "admin")
8- Go to Users and edit admin
9- Enter a new password
10- Have fun :)