Short python program to change voltages in rpi gpio pins.

December 23, 2012

First I installed python:

sudo apt-get install python-pip

and then a library for gpio:

sudo pip install rpi.gpio

Once that was done, the following python script sets a high and low voltage to physical pin 11. Note: the physical pin 11 corresponds to GPIO 17.  The physical pin 6 corresponds to Ground.  For additional details and diagrams refer to: http://elinux.org/RPi_Low-level_peripherals.

import RPi.GPIO as GPIO
import time
for i in range(5):
   print ‘——————‘
   print ‘now in repetition:’,i
   GPIO.setmode(GPIO.BOARD)
   GPIO.setup(11,GPIO.OUT)
   print ‘ON…’
   GPIO.output(11,GPIO.HIGH)
   time.sleep(5)
   GPIO.output(11,GPIO.LOW)
   print ‘OFF…’
   time.sleep(5)

To run the program above, I created a script prendeApaga.py and ran it as shown below:

sudo python prendeApaga.py

Note: additional information for the rpi unit:

linux distribution: ID=debian

user: pi

password: raspberry

 available from: MCM electronics: http://www.mcmelectronics.com/

How to setup a headless rpi

December 23, 2012

I came across this link http://penguintutor.com/linux/raspberrypi-headless and followed the advise of trying to find out the dhcp address.

I connected the rpi via an ethernet cable to my wireless router and booted the rpi.

Then using ipconfig  gives the Default Gateway of my wireless router, x.x.x.1.  Then I noticed the IP address of my laptop, from which I run Putty: it is under IP Address: x.x.x.4.  Since I connected the ethernet cable for the rpi next to the cable of the laptop, to the right, I tried x.x.x.5 and it worked!

Picking a private Health Insurance

May 20, 2011

Recently we needed to go for private insurance.  We found out that the HMO and POS were in general less costly, followed by PPO and finally came the Indemnity.

Below it is a simplified example to illustrate the differences and relationship between deductible and out of pocket max.

A couple of important pointers:

1. There are several web pages that point out to the importance of looking into the Lifetime Maximum per insured.  The one we selected shows $4,000,000+

2. Annual Deductible.  “The amount a member must pay for medical services before their health plan begins to pay for covered services. Some services are exempt from the annual deductible” http://www.fuzeqna.com/pebb/consumer/kbdetail.asp?kbid=533.  For example, say the plan charges 35% for Hospital Admission after deductible.  and the deductible is $6000 / family.  If the Hospital cost is $12,000 then the cost on the member is 12000 – 6000 = 6000 (to meet the deductible) + 2100  (2100 = 35%*6000).  Total cost to the member $8,100.

3. Annual Out of Pocket: “The max total you pay out of pocket for most covered services in a calendar year.  After you reach that maximum, the plan will pay for most covered services at 100%”.  For example.  Say the insurance out of pocket max is $11,000.  In the above example the member paid already $8,100.  If another charge comes along the member will need to pay $2,900 (11000-8100) and since the member hit the max out of pocket the insurance will pay after-wards.

Using WatiN to test browse Yahoo mail.

May 27, 2009

Summary:

The objective of this exercise is to compare testing of a web site (Yahoo Mail) with WatiN to the test previously done with AutoIt:

Automating Internet Explorer with Auto It. (Windows Tasks Automation software)

The first major advantage is the availability of the Test Recorder. This Test Recorder is able to get the names or id’s (and other properties) of the IExplorer. The Test Recorder is available from: http://watintestrecord.sourceforge.net/ A big plus is that it can generate source code in VB.NET. (The beta 2 version is not generating C# code at the moment)

TestRecorderSmall

Note: the note in red in the above capture: “Scripting to VB.Net and copying to clipboard.”

I modified the example shown in: http://watin.sourceforge.net/gettingstarted.html in order to have the code in C# to access http://mail.yahoo.com, login, and click on Mail.

I have a video that shows the recording process and the code generated using the Test Recorder:

Notice that the example is done with Visual Studio 2003. Since I used Visual Studio Express 2005 there is a minor difference: when adding the Reference to the Project, I needed to click on the Browse tab.

During this exercise I came across the need to address the log-in button in Yahoo but it was not obvious how to invoke it. Then I ran the recorder, compiled the script to VB.Net Console and then copied the results to the console. The button I needed was: Button btn_save = window.Button(Find.ByName(“save”));

Since I am using the C# version I coded the call to the button as:

ie.Button(Find.ByName(“.save”)).Click();

Notes:

1. A useful tool to find out the names, id’s, etc of IExplorer fields is the ie developer toolbar.

2. Here is the C# code:

//**WatiN example**
// Adapted by Omar Flores
//
using System;
using WatiN.Core;
using System.Threading;

namespace WatiNGettingStarted
{
class WatiNConsoleExample
{
[STAThread]
static void Main(string[] args)
{
// Open a new Internet Explorer window and
// goto the google website.
IE ie = new IE(“http://www.mail.yahoo.com”); //(“http://localhost/”);

// Find the search text field and type Watin in it.
ie.TextField(Find.ByName(“login”)).TypeText(“yourUserID”);
Thread.Sleep(2000);

// Find the search text field and type Watin in it.
ie.TextField(Find.ByName(“passwd”)).TypeText(“yourPassword”);
Thread.Sleep(2000);

// Click the Google search button.
ie.Button(Find.ByName(“.save”)).Click();
Thread.Sleep(1000);

// Click the Google search button.
ie.Button(Find.ById(“global_check_mail_top”)).Click();
Thread.Sleep(1000);

// Uncomment the following line if you want to close
// Internet Explorer and the console window immediately.
//ie.Close();
}
}
}

Load / Stress Testing Using Pylot ver. 1.24.

May 15, 2009

Summary:

Load testing in a web server has been performed in order to find out if response times meet requirement.

The load test was carried with one user using a python script that sends requests every 110ms over a time span of 1hour.

In order to have multiple users, an open source package called pylot was used. This python bases web testing tool allows to have multiple virtual users through the use of threads.

The Results show that the web site visited: gmail behaves rather well though occasional spikes in the response time are seen.

Notice the spike that shows in the 42nd attempt.

The script used can be found in:

https://florespino.wordpress.com/2009/03/26/load-testing-a-web-server/

Using Pylot – an open source python package.

The use of open source is considered below. The program can be found in: http://www.pylot.org/

Version recommended: 1.24.  Although the results below show version 1.22, a defect in version 1.22 caused the reports to fail if the web site experienced a time-out.  This has been corrected in ver 1.24.

The following sample run has been done using the following Test parameters:

number of agents: 1

test duration in seconds: 60

rampup in seconds: 0

interval in milliseconds: 500

test case xml: c:\tmp\testcase.xml

log messages : False

The process can be started with the graphical user interface, which is invoked with the –g at the end of the python command:

C:\Tmp\pylot_1.22\pylot_1.22>python run.py -g.  Notice that the test case is specified in the file test cases.xml, which is located in the pylot_1.22\pylot_1.22 folder.

Pylot – GoogleMail Performance Results

report generated: 05/06/2009 12:08:06
test start: 05/06/2009 12:07:06
test finish: 05/06/2009 12:08:04

Workload Model

test duration (secs)

58

agents

1

rampup (secs)

0

interval (millisecs)

500

Results Summary

requests

35

errors

0

data received (bytes)

643637

Response Time (secs)

Throughput (req/sec)

Frame1

Frame2

Response Time

Throughput

Timer Groups – Response Times

Timer Group

Count

avg

stdev

min

50th %

80th %

90th%

95th %

99th %

max

default_timer

35

1.711

0.561

1.395

1.505

1.603

2.626

2.895

4.010

4.010

Agent Details

Agent

Requests

Errors

Bytes Received

Avg Response Time (secs)

1

35

0

643637

1.711

Fastest Responding Requests

Request URL

Avg Response Time (secs)

http://mail.google.com/mail/#inbox

1.711

Slowest Responding Requests

Request URL

Avg Response Time (secs)

http://mail.google.com/mail/#inbox

1.711

Using three agents:

Notice how the Response Times are higher, as well as the throughput:

Response Time

Throughput

Ramp-up time

The following is an example that introduces the concept of ramp-up time1.

Pylot – Web Performance Results

http://www.pylot.org/samples/results/results.html

report generated: 08/10/2007 12:19:58
test start: 08/10/2007 12:09:58
test finish: 08/10/2007 12:19:57

Workload Model

test duration (secs)

600

Agents

10

rampup (secs)

600

interval (millisecs)

0

Results Summary

Requests

2202

Errors

0

data received (bytes)

87285078

Response Time (secs)

Throughput (req/sec)

Frame3

Frame4

Response Time

Throughput

Agent Details

Agent

Requests

Errors

Bytes Received

Avg. Response Time

1

484

0

19185276

1.24

2

408

0

16172712

1.32

3

340

0

13477260

1.41

4

278

0

11019642

1.51

5

223

0

8839497

1.61

6

169

0

6698991

1.77

7

128

0

5073792

1.86

8

89

0

3527871

2.01

9

57

0

2259423

2.10

10

26

0

1030614

2.30

Appendix:

Other sample discussions:

On Automating Windows Tasks

Using sqlite to convert a csv file to a database, and viceversa!

Uninstalling Microsoft Sharepoint Services x64

1  Ramp-up Time:

To find out if your hardware is robust enough to handle a certain number of users simultaneously accessing the application, you want to do a stress test. A stress test progressively increases the load of the application to discover the different breaking points  -ref: http://java.sys-con.com/node/782824/mobile

The test results should answer the following questions:

* How many users can the application handle while maintaining an acceptable response time?

* What is the load threshold above which the server begins to generate errors and/or refuse connections?

* Does the server remain functional under high load or does it crash?

To do a stress test, testers should ramp up the load, starting from normal and up to the maximum predicted limit, and monitor the response times and error rates. A sudden change indicates that a threshold has been passed.

Automating Internet Explorer with Auto It. (Windows Tasks Automation software)

May 7, 2009

Summary:

This article presents the automation of browsing using Internet Explorer and a commercial email provider: Yahoo.

Auto It was used to:

1. automatically start Internet Explorer,

2. login to Yahoo (if the user was not using the option auto-login) via sending key strokes,

3. and then to open the Inbox using the mouse.

Introduction:

Auto It is a free-ware application: http://www.autoitscript.com/autoit3/downloads.shtml

It has a set of functionality that can be readily deployed, i.e., a utility that provides the windows’ names, mouse coordinates, etc.  The caption is shown below:

AutoItWindowDetection

To start a program we issue the command: Run(“C:\Program Files\Internet Explorer\iexplore.exe”)

Since automation is accomplished using the windows’ names, the window name is used:

WinWaitActive(“Google – Windows Internet Explorer”)

The script is shown at the end.

Brief description of the script:

Two functions have been defined: login() and go2inbox().

The login function waits until the Yahoo! Mail window is active and then sends keystrokes (user id, tab, password, tab, enter) in order to access the email provider.

The go2inbox also waits until the Yahoo! Mail window is active and then it controls the mouse and directs it to the coordinates specified with:

MouseClick(“left”,45,505,1)   –Notice that the IExplore window must be maximized.

Notes:

Handling the active windows takes the following into consideration:

1. If some windows have similar title but not exactly the same, and still they need to be considered as the same (Yahoo! Mail is common for login and for inbox.  But the exact names differ.  Auto It provides a way to use a substring of the name)

2. If tabbing doesn’t work in a certain window, mouse click is the alternative.

3. When browsing some window the info doesn’t appear immediately.  It is advisable to use the sleep function with a time of 5 seconds to ensure the needed control is available.

Script:

; AutoIt Version: 3.0
; Language:       English
; Platform:       WinXP
; Author:         Omar Flores (omar.flores.i.t@gmail.com), modified from an example by Jonathan Bennett (jon@hiddensoft.com)
; Script Function:
;   Opens IExplorer, types mail.yahoo.com, logs in, checks the inbox.
;
Opt(“WinTitleMatchMode”, 2)  ;match substring of window

; Prompt the user to run the script – use a Yes/No prompt
$answer = MsgBox(4, “AutoIt Example (English Only)”, “This script will run IExplorer, browse to YahooMail, login and check the Inbox.  Run?”)

; Check the user’s answer to the prompt (see the help file for MsgBox ;return values),If “No” was clicked (7) then exit the script
If $answer = 7 Then
MsgBox(0, “AutoIt”, “OK.  Bye!”)
Exit
EndIf

; Run IExplorer
Run(“C:\Program Files\Internet Explorer\iexplore.exe”)

; Wait for the IExplorer to become active – it is titled “Google – Windows Internet Explorer” on English systems
WinWaitActive(“Google – Windows Internet Explorer”)
Sleep(1000)
send(“{tab 11}”)  ;to be in the url location

Sleep(2000)
Send(“mail.yahoo.com{Enter}”)   ;type the yahoo mail url

login()   ;if the yahoo user has signed out, then login will sign in.
copymail function
go2inbox()

Func login()
WinWaitActive(“Yahoo! Mail”)
if WinExists(“Yahoo! Mail: The best web-based email! – Windows Internet Explorer”) then
Send(“florespino”)
Sleep(1500)
send(“{TAB}password”)
sleep(2500)
send(“{TAB 2}{Enter}”)
endif

EndFunc

Func go2inbox()
WinWaitActive(“Yahoo! Mail”)  ;WinWaitActive(“Yahoo! Mail”,3) didn’t work, I removed the 3.
if WinExists(“Yahoo! Mail”) Then
sleep(5000)
MouseClick(“left”,45,505,1)  ;ONLY worked with full size window!  Otherwise the window always moved.
EndIf
EndFunc

Omar Flores

System Integration Test Engineer

Omar.flores.i.t@gmail.com

Load Testing a Web server

March 26, 2009

Python script used to send requests to a web server.  You can specify the number of requests in the function testIt, changing the upper limit in the range from 5 to the desired number.  Each request is sent every .1 sec.

import urllib

import os

import datetime

import time

def fileremove(f):

if os.path.exists(f):

os.remove(f)

def stressTest(link,i):

f=open(r’c:\tmp\Response.txt’,’a’)

mypath = link

mylines = urllib.urlopen(mypath).readlines()

time= datetime.datetime.now()

f.write(str(i)+’,’+str(time.second)+’,’+mylines[1])

f.write(‘\n’)

print i, str(time.second)+’ ‘+mylines[1]

f.close()

def testIt():

f=r’/Users/YourName/Desktop/Response.txt’

fileremove(f)

for i in range(1,5):

stressTest(“http://mail.google.com/”,i)

if __name__ == “__main__”:

testIt()

Using sqlite to convert a csv file to a database, and viceversa!

March 19, 2009

This short post shows the commands needed to:

1. Convert from a csv file to a database and

2. Convert from a database to a csv file.

1. Csv file to sqlite db.

1.1 suppose your data is in a text file names.txt in the format:

1,name1,lastName1

2,name,lastName2

Then the first thing is to create a table with such structure (http://www.sqlite.org/sqlite.html)

sqlite3 mydb   –note: this creates the sqlite db ‘mydb’

sqlite>create table mytable(id integer, name text, lastname text);

sqlite>.tables

mytable

sqlite> .mode list
sqlite> .separator ,
sqlite> .import names.txt mytable   –note: DON’T use ; after mytable
sqlite> select * from mytable;

1,Omar,Flores
2,Mike,Flores

Now for the second part:

2. table to csv file.

sqlite> .mode list   –if you entered these before, no need to enter again.
sqlite> .separator ,

sqlite> .output namesexported.txt
sqlite> select * from mytable;
sqlite> .exit

edit the file namesexported.txt. It should show:

1,Omar,Flores
2,Mike,Flores

That is it. Simple and fast.

Omar

Uninstalling Microsoft Sharepoint Services x64

February 3, 2009

Uninstalling Sharepoint Services in a 64 bit server with Windows 2003 SP2 by using add/remove programs leaves behind some internal databases.

Furthermore, uninstalling it appears to have an impact in IIS, wherefore IIS needed to be uninstalled, reinstalled.

Here are the steps followed, part of them found ‘googling’ for Sharepoint Services x64 uninstallation / IIS uninstallation.

1. Remove SharepointServices using add/remove programs.
2. Go to C:\Windows\SYSMSI\SSEE\MSSQL.2005\MSQL\DATA and manually
 remove all sharepoint internal databases
(google_article)
3. Remove IIS
4. Reboot the machine
5. run aspnet_regiis –ir (notice that if you run
aspnet_regiis -i in the x64 system it not only doesn't work but
the message that appears seems to imply the need to look for
another application that does the same task.)
6. Go to add/remove > Microsoft .net2.0 Framework service pack 1
> CHANGE.
7. Go to IIS Manager, Web Service Extension - ASP.NET v2.0.50727
set it to Allow
8. Reinstall Sharepoint.  Notice that the default web site is
disabled. Enable it and thus the process ends.

After going through the above steps the installation worked reliably.

Omar

On Automating Windows Tasks

February 1, 2009

The past month I was assigned the task of automating the installation of a software package that uses msi files and then setup dialog windows.
Python (download_Python) has excelent libraries for this task:
Python Windows Automation

There is a great video that demonstrates the usage of the pywinauto: pywinauto_video

Follow the instructions in the page to download it (download_Pywinauto) and install it.
The above program will allow you to open and identify windows and control buttons using the application class, that can be found in the file application.py
Notice there that the combo boxes are controlled using its name. Internally the tool finds the window’s handle.
For some applications the window’s fields are hard to handle. This is because the fields don’t have unique names.
The way to handle this situation is to tab around the page until you land in the right field.
To this end download the Sendkeys tool, also in the page (download_Sendkeys). Make sure that you select the ‘Binaries’ download. Select the version that corresponds to the python version you have installed.
Once you have installed these two tools you can start controlling the windows and its contents.
Omar Flores