<$BlogRSDUrl$>

Friday, June 05, 2015

Minimal Netflow Sensor Station with OpenBSD 5.7 

The basics:

Default install of OpenBSD 5.7 amd64.

I start ntpd by default so I'll have accurate time stamps in my logs.
Get the network interfaces up and running.

In the default /etc/pf.conf rules, add the following line to the top:
set state-defaults pflow

Add the following to /etc/hostname.pflow0
flowsrc 127.0.0.1 flowdst 127.0.0.1:12345

Then "pkg_add flowd" to install the collector.  By default it listens only on localhost port 12345.

Add "/usr/local/sbin/flowd" to /etc/rc.local to cause it to start at boot.

It will start logging to /var/log/flowd

You can view the netflow logs with "flowd-reader /var/log/flowd"

More advanced:

We'll use the nfdump tools for our collector and reporting.

pkg_add nfdump

The nfcapd netflow capture daemon will replace flowd, and listens on port 9995 by default.  Modify /etc/hostname.pflow0 to contain the following:
flowsrc 127.0.0.1 flowdst 127.0.0.1:9995

Also, modify /etc/rc.local and remove the line that starts flowd, and replace it with (all on one line):
/usr/local/bin/nfcapd -D -z -w -n localhost,127.0.0.1,/var/log/netflow -T all -S 2

You will also need to create the /var/log/netflow directory.

You can now use the nfdump tool to view one of the files which are created every 5 minutes.  Files are in sub-directories based on year, month, day, hour. For example:
nfdump -r /var/log/netflow/2015/06/05/13/nfcapd.201506051335 -s dstip

Or to view them all use the capital R option:
nfdump -R /var/log/netflow/2015/06/05/13 -s dstip

If you are already in a particular directory, use the back tic around the pwd command:
nfdump -R `pwd` -s dstip

You can also select other stats like dstport, etc.  Here are some of them.  See the man page for more.
recordStatistic about aggregated netflow records.
srcipStatistic about source IP addresses
dstipStatistic about destination IP addresses
ipStatistic about any (source or destination) IP addresses
srcportStatistic about source ports
dstportStatistic about destination ports
portStatistic about any (source or destination) ports
protoStatistic about protocol numbers



There is also a filter syntax if you wanted to look for a particular IP address for example, surround the filter expression by single quotes (different from the back tic):
nfdump -R `pwd` 'IP 10.1.100.10'

Using a Different Sensor 

Why don't we try softflowd as a sensor.  You can undo all the /etc/pf.conf and /etc/hostname.pflow0 stuff. The new daemon will listen promiscuously to the network, sof the pf packet filter doesn't need to be involved. "pkg_add softflowd"

Now go ahead and edit /etc/rc.conf.local and add the following lines (and change bge0 to whatever your network interface is):

pkg_scripts=softflowd
softflowd_flags="-i bge0 -n 127.0.0.1:9995"


Reboot to do the lazy start of all daemons. You can check to make sure it is all working by issuing the command:softflowctl statistics
 


Saturday, November 09, 2013

Insignia Infocast 8 Silvermoon Chumby Boot 

The poor Chumby wont' boot any more.
I suspected a bad SD card, so I went out and bought a new 2GB one, opened up the bottom of the Infocast, and pulled the microSD card.  The card did seem to have bad blocks, at least according to the Linux machine I used to read it.
I put the OEM image in the new card: http://files.chumby.com/firmware/infocast8/1.0.5/rom-silvermoon_a0.img.zip

Still won't boot.

Here is the serial output.

  ....................................................................................................

Total times UART was inited: 0x00000001

Total wait loops iterated: 0x000022B3

Hello world, I'm the most incredibly annoying boot process you'll ever meet!

key waiting

done with key wait

key waiting2

flash boot attempt

loading OS loader

chumby!

disableIRQ

setupxfer

levelling up...

MPMU_PLL1_REG1: 10010264, MPMU_PLL1_REG2: 82000000
MPMU_PLL2_REG1: 90020364, MPMU_PLL2_REG2: 82000040
MPMU_PLL2CR: 00096f00, MPMU_FCCR: 40000000
MPMU_ACGR: 007ffffe, APMU_CCR: 8f0082c0
TMR_CR1: 1952943
TMR_CR1: 1961471

IRQ mask: 00000001 00000040
IDLE: 00000300  APCR: 00000000
MC_HW_SLP: 00000000  MC_SLP_REQ: 00000000
TMR_SR1: 00000000  TRM_IER1: 00000000
APMU_RES_FRM_SLP_CLR: 00000000
Calling function in sram (d1020000)
..|022|.@ˇo|011|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|011

.2+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|022

!*#

IRQ mask: 00000001 00000040
IDLE: 00000300  APCR: ea000014
MC_HW_SLP: 00000000  MC_SLP_REQ: 00000000
TMR_SR1: 00000000  TRM_IER1: 00000000
APMU_RES_FRM_SLP_CLR: 00000000
Returned from function.  Waiting for IRQs to hit (2108542 vs 2038824)
Timer IRQ should have hit!  Did it?!
IRQ mask: 00000001 00000040
IDLE: 00000300  APCR: 00000000
MC_HW_SLP: 00000000  MC_SLP_REQ: 00000000
TMR_SR1: 00000000  TRM_IER1: 00000000
APMU_RES_FRM_SLP_CLR: 00000000
MPMU_PLL1_REG1: 91040664, MPMU_PLL1_REG2: 84000030
MPMU_PLL2_REG1: 90020464, MPMU_PLL2_REG2: 84000070
MPMU_PLL2CR: 00097300, MPMU_FCCR: 4000c290
MPMU_ACGR: 007effde, APMU_CCR: 8fc082c0
updating DDR config (again)...
DDR PHY DLL delay values: 0057
reading back DDR config...done.


U-Boot 2009.01-rc1-svn60940 (Dec 09 2010 - 13:04:59)
Marvell version: 1.1.1.1 PXAxxx


                .:+I$ZOOOZZZZOO~       
             .7OZZZZZZZZZZZZZZZZ?      
            ,ZZZZZZZZZZZZZZZZZZZO      
            ZZZZZZ?ZZZZZZOI$ZZZZO.     
           .OZZZ=?OI~ZZZO Z~?ZZZO.     
            ZZZZ~7O7:OZZO~  ZZZZO      
            IZZZZOOOZZZZZZZZZZZZ$      
            =ZZZZZZZZZZZZZZZZZZZI      
            IZZZZZZZZZZZZZZZZZZZI      
     :IZOOZZZZZZZZZZZZZZZZZZZZZZZZ,    
  ,ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ   
.Z$$7?~,..~OZZZZZZZZZZZZZZZZZ7 =ZZZZO, 
         IZZZZ$,OZZZZZZZO+ZZZO.  ,ZZZO 
        ZZZZ~ ~ZZZZ ?ZZZ~ ?ZZZZ     .=+
       ,ZZO  .OZZZ  ZZZO   OZZZ        
       :Z$   IZZZ, .OZZZ   .OZZ.       
       .~    ZZO.  .OZZ+     $Z        
             Z+     $ZZ                
                    .?                 
     /\ \                        /\ \                 
  ___\ \ \___   __  __    ___ ___\ \ \____  __  __    
 /'___\ \  _ `\/\ \/\ \ /' __` __`\ \ '__`\/\ \/\ \   
/\ \__/\ \ \ \ \ \ \_\ \/\ \/\ \/\ \ \ \L\ \ \ \_\ \  
\ \____\\ \_\ \_\ \____/\ \_\ \_\ \_\ \_,__/\/`____ \ 
 \/____/ \/_/\/_/\/___/  \/_/\/_/\/_/\/___/  `/___/> \
                                                /\___/
[silvermoon_a0                           ]      \/__/ 

MARVELL PXAXXX series.
Based on 88SV331xV5 Core with ARM926 LE CPU.
Stepping A0 CPU conf 750819->750919 ARM CPUID 41159265->56158400
Code original base is u-boot-arm 2009.01-rc1.

DDR PHY DLL delay values: 0055
DRAM:  128 MB
MMC:  pxa-sdh: 0
Using default environment

Initializing LCD at address 0x0112b000 (updating 42 registers)
Setting d420b0c0 -> 0112b000: 0112b000
Setting d420b0c4 -> 0112b000: 0112b000
Setting d420b0c8 -> 0112b000: 0112b000
Setting d420b0f4 -> 0112b000: 0112b000
Setting d420b0f8 -> 0112b000: 0112b000
Setting d420b0e0 -> 00000640: 00000640
Setting d420b0ec -> 02580320: 02580320
Setting d420b0f0 -> 02580320: 02580320
Setting d420b0fc -> 00000640: 00000640
Setting d420b104 -> 02580320: 02580320
Setting d420b108 -> 02580320: 02580320
Setting d420b114 -> 028c049f: 028c049f
Setting d420b118 -> 02580320: 02580320
Setting d420b11c -> 00d70028: 00d70028
Setting d420b120 -> 0022000e: 0022000e
Setting d420b148 -> 80000000: 80000000
Setting d420b14c -> 00000640: 00000960
Setting d420b154 -> 00000640: 00000960
Setting d420b15c -> 000000ff: 00000000
Setting d420b164 -> e0400000: 7226b840
Setting d420b168 -> 6028c838: 6022d828
Setting d420b170 -> 00020000: 00020000
Setting d420b174 -> 5119824c: 0021c370
Setting d420b178 -> 03000000: 03000000
Setting d420b17c -> 00000004: 00000008
Setting d420b180 -> 02000f0e: 02000f0e
Setting d420b184 -> 00008808: 00008808
Setting d420b1a4 -> 0000e000: 0000e000
Setting d420b1a8 -> 80000007: 80000007
Setting d420b1ac -> 00004000: 00004000
Setting d420b1b0 -> 20004000: 20004000
Setting d420b1b4 -> 00004000: 00004000
Setting d420b1bc -> 00000002: 00000002
Setting d420b1c0 -> 88000000: 88000000
Setting d420b1c4 -> 44c0018c: 44c01308
Setting d420b1c8 -> 00000005: 00000005
Setting d420b1cc -> d420b000: 00000000
Setting d4019020 -> 00100000: 00000000
Setting d401905c -> 00100000: 00000000
Setting d420b1b8 -> 210ff10f: 210ff10f
Setting d420b190 -> 08001110: 08001110
Setting d420b194 -> 20020081: 20020081
In:    serial
Out:   serial
Err:   serial
Hit any key to stop autoboot:  0 
Determining boot partition...
Active partition: 0
Found part number: 272 1001
Drawing something to the screen...
Clearing screen to black...
Clearing gl buffer...
Clearing flake buffer...
Precalculating snow LUT...
Testing the touchscreen...

12307 bytes read
Unzipping...
Precalculating RAND LUT...
Press Control-C to enter a shell.
Continuing boot...
Testing the touchscreen again...
Booting to regular shell...

14356 bytes read
Unzipping...
Precalculating RAND LUT...
Booting to rfsA...

2078040 bytes read
Ready to boot zImage from 500000


Starting kernel using machid 1829 (0x725) ...

Uncompressing Linux.................................................................................................................................................................. done, booting the kernel.
[    0.000000] Linux version 2.6.28-M2.1.8.12 (builder@stormbuild) (gcc version 4.3.2 (Sourcery G++ Lite 2008q3-72) ) #1 Thu Dec 9 13:04:27 PST 2010
[    0.000000] CPU: Marvell Mohawk [56158400] revision 0 (ARMv5TE), cr=04053977
[    0.000000] CPU: VIVT data cache, VIVT instruction cache
[    0.000000] Machine: PXA168-based Chumby Silvermoon platform
[    0.000000] Ignoring unrecognised tag 0x54410008
[    0.000000] Memory policy: ECC disabled, Data cache writeback
[    0.000000] Built 1 zonelists in Zone order, mobility grouping off.  Total pages: 32512
[    0.000000] Kernel command line: root=/dev/mmcblk0p2 rootfstype=ext3 rootwait console=ttyS0,115200 mem=128M uart_dma init=/linuxrc sysrq_always_enabled ro logo.brand=insignia
[    0.000000] debug: sysrq always enabled.
[    0.000000] PID hash table entries: 512 (order: 9, 2048 bytes)
[    0.000088] Console: colour dummy device 80x30
[    0.000106] ram_console: buffer 00000000, invalid size 0, datasize -12
[    0.000185] Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
[    0.000479] Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
[    0.006772] Memory: 128MB = 128MB total
[    0.006795] Memory: 123904KB available (3852K code, 934K data, 1060K init)
[    0.006886] SLUB: Genslabs=12, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.006909] Calibrating delay loop... 796.26 BogoMIPS (lpj=3981312)
[    0.220326] Mount-cache hash table entries: 512
[    0.220656] CPU: Testing write buffer coherency: ok
[    0.223461] net_namespace: 292 bytes
[    0.223663] NET: Registered protocol family 16
[    0.224157] silvermoon.c - silvermoon_init():701 - Just so you know, the CPU type is 0x56158400
[    0.224270] pxa168_mfp_set_fastio_drive config changed to 2000
[    0.224521] silvermoon_init() - attempting to add SSP2 for touchscreen
[    0.224536] silvermoon_ssp_init() adding ssp2
[    0.224588] silvermoon_ssp_init() exit
[    0.224637] silvermoon_init() - adding u2h ehci usb hub
[    0.224809] silvermoon_init() - adding MMC3 init[2], wifi MMC1
[    0.225198] platform_driver_register
[    0.228050] SCSI subsystem initialized
[    0.228176] usbcore: registered new interface driver usbfs
[    0.228275] usbcore: registered new interface driver hub
[    0.228420] usbcore: registered new device driver usb
[    0.251044] NET: Registered protocol family 2
[    0.340431] IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.340628] TCP established hash table entries: 4096 (order: 3, 32768 bytes)
[    0.340719] TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
[    0.340787] TCP: Hash tables configured (established 4096 bind 4096)
[    0.340803] TCP reno registered
[    0.370442] NET: Registered protocol family 1
[    0.381514] Installing knfsd (copyright (C) 1996 okir@monad.swb.de).
[    0.382594] NTFS driver 2.1.29 [Flags: R/W].
[    0.383040] fuse init (API version 7.10)
[    0.383643] msgmni has been set to 242
[    0.384696] alg: No test for stdrng (krng)
[    0.384758] io scheduler noop registered
[    0.384771] io scheduler anticipatory registered
[    0.384785] io scheduler deadline registered
[    0.384903] io scheduler cfq registered (default)
[    0.392931] pxa168fb_ovly.c - pxa168fb_probe():2075 - Just pointed fb0 at 0112b000
[    0.396405] pxa168fb_set_par() warning: viewport x/y zoom were 0
[    0.411332] Console: switching to colour frame buffer device 100x75
[    0.435993] pxa168fb_ovly: frame buffer device was loaded to /dev/fb0 .
[    0.440882] pxa2xx-uart.0: ttyS0 at MMIO 0xd4017000 (irq = 27) is a FFUART
[    0.440915] console [ttyS0] enabled
[    0.762044] pxa2xx-uart.2: ttyS2 at MMIO 0xd4026000 (irq = 29) is a STUART
[    0.769289] brd: module loaded
[    0.773648] loop: module loaded
[    0.776862] logger: created 64K log 'log_main'
[    0.781406] logger: created 256K log 'log_events'
[    0.786162] logger: created 64K log 'log_radio'
[    0.790795] usbcore: registered new interface driver cdc_ether
[    0.796697] Driver 'sd' needs updating - please use bus_type methods
[    0.803189] usbmon: debugfs is not available
[    0.807461] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    0.814187] u2h regbase 0xc883a000 phybase 0xc883e000 irq 51
[    0.819996] pxa168_usb_phy_init 254: calibrate timeout, UTMI_PLL 7e01aeeb
[    0.828509] pxau2h-ehci pxau2h-ehci: Marvell PXA SOC EHCI Host Controller
[    0.835504] pxau2h-ehci pxau2h-ehci: new USB bus registered, assigned bus number 1
[    0.843301] pxau2h-ehci pxau2h-ehci: irq 51, io base 0x0883a000
[    0.860382] pxau2h-ehci pxau2h-ehci: USB 2.0 started, EHCI 1.00
[    0.866624] usb usb1: configuration #1 chosen from 1 choice
[    0.872420] hub 1-0:1.0: USB hub found
[    0.876198] hub 1-0:1.0: 1 port detected
[    0.880710] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002
[    0.887509] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.894779] usb usb1: Product: Marvell PXA SOC EHCI Host Controller
[    0.901076] usb usb1: Manufacturer: Linux 2.6.28-M2.1.8.12 ehci_hcd
[    0.907340] usb usb1: SerialNumber: pxau2h-ehci
[    0.911908] [ehci-pxau2h.c] Silvermoon media insertion / removal detection enabled
[    0.919558] Initializing USB Mass Storage driver...
[    0.924564] usbcore: registered new interface driver usb-storage
[    0.930606] USB Mass Storage support registered.
[    0.935301] usbcore: registered new interface driver libusual
[    0.941224] u2o regbase 0xc8842000 phybase 0xc8846000 irq 44
[    0.947995] mice: PS/2 mouse device common for all mice
[    0.953714] mmp-rtc mmp-rtc: rtc core: registered mmp-rtc as rtc0
[    0.960116] mmc0: SDHCI controller on MMC [pxa-sdh.0] using ADMA
[    0.966334] mmc1: SDHCI controller on MMC [pxa-sdh.1] using ADMA
[    0.972537] mmc2: SDHCI controller on MMC [pxa-sdh.2] using ADMA
[    0.978584] pxa-sdh: Secure Digital Host Controller Interface driver
[    0.984972] pxa-sdh: Copyright(c) Pierre Ossman
[    0.990421] usbcore: registered new interface driver usbhid
[    0.995998] usbhid: v2.6:USB HID core driver
[    1.000412] Advanced Linux Sound Architecture Driver Version 1.0.18rc3.
[    1.007030] ALSA device list:
[    1.009994]   No soundcards found.
[    1.013421] oprofile: using timer interrupt.
[    1.018024] TCP cubic registered
[    1.021296] NET: Registered protocol family 17
[    1.026365] RPC: Registered udp transport module.
[    1.031117] RPC: Registered tcp transport module.
[    1.035821] XScale iWMMXt coprocessor detected.
[    1.040778] pxa168fb.c - pxa168fb_probe():1268 - Changing LCD_SPU_DMA_CTRL1 from 0x20020081 -> 0x2002ff81
[    1.062876] pxa168fb.c - pxa168fb_probe():1328 - Changing LCD_SPU_DMA_CTRL0 from 0x08401111 -> 0x08441111
[    1.072474] pxa168fb.c - pxa168fb_probe():1331 - Changing LCD_SPU_DMA_CTRL1 from 0x2002ff81 -> 0x2002ff81
[    1.082297] pxa168fb: frame buffer device was loaded to /dev/fb1 .
[    1.089960] silvermoon_lcd_power() ON
[    1.093812] mmp-rtc mmp-rtc: setting system clock to 1970-01-01 00:00:00 UTC (0)
[    1.101418] Waiting for root device /dev/mmcblk0p2...
[    1.295759] usb 1-1: new high speed USB device using pxau2h-ehci and address 2
[    1.701385] usb 1-1: configuration #1 chosen from 1 choice
[    1.751103] hub 1-1:1.0: USB hub found
[    1.798917] hub 1-1:1.0: 4 ports detected
[    1.936206] usb 1-1: New USB device found, idVendor=058f, idProduct=6254
[    1.942952] usb 1-1: New USB device strings: Mfr=0, Product=1, SerialNumber=0
[    1.950087] usb 1-1: Product: USB2.0Hub
[    2.529077] usb 1-1.4: new high speed USB device using pxau2h-ehci and address 3
[    3.111905] usb 1-1.4: configuration #1 chosen from 1 choice
[    3.206303] scsi0 : SCSI emulation for USB Mass Storage devices
[    3.213272] usb 1-1.4: New USB device found, idVendor=058f, idProduct=6366
[    3.220156] usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[    3.227519] usb 1-1.4: Product: Mass Storage Device
[    3.232421] usb 1-1.4: Manufacturer: Generic
[    3.236689] usb 1-1.4: SerialNumber: 058F0O1111B1
[    3.950392] mmc1: new SDIO card at address 0001
[    4.987701] mmc2: new high speed SD card at address 1234
[    4.993345] mmcblk0: mmc2:1234 SA02G 1.85 GiB 
[    4.997937]  mmcblk0:<4>mmcblk0: retrying using single block read
[    5.004324] mmcblk0: error -110 sending read/write command, response 0x0, card status 0x400b00
[    5.012967] end_request: I/O error, dev mmcblk0, sector 0
[    5.018415] mmcblk0: error -110 sending read/write command, response 0x0, card status 0x400b00
[    5.027062] end_request: I/O error, dev mmcblk0, sector 1
[    5.032678] mmcblk0: error -110 sending read/write command, response 0x0, card status 0x400b00
[    5.041327] end_request: I/O error, dev mmcblk0, sector 2
[    5.046778] mmcblk0: error -110 sending read/write command, response 0x0, card status 0x400b00
[    5.055420] end_request: I/O error, dev mmcblk0, sector 3
[    5.060896] mmcblk0: error -110 sending read/write command, response 0x0, card status 0x400b00
[    5.069505] end_request: I/O error, dev mmcblk0, sector 4
[    5.074988] mmcblk0: error -110 sending read/write command, response 0x0, card status 0x400b00
[    5.083632] end_request: I/O error, dev mmcblk0, sector 5
[    5.089079] mmcblk0: error -110 sending read/write command, response 0x0, card status 0x400b00
[    5.097721] end_request: I/O error, dev mmcblk0, sector 6
[    5.103196] mmcblk0: error -110 sending read/write command, response 0x0, card status 0x400b00
[    5.111842] end_request: I/O error, dev mmcblk0, sector 7
[    5.117244] Buffer I/O error on device mmcblk0, logical block 0
[    5.123304] mmcblk0: retrying using single block read
[    5.128410] mmcblk0: error -110 sending read/write command, response 0x0, card status 0x400b00
[    5.137206] end_request: I/O error, dev mmcblk0, sector 0
[    5.142706] mmcblk0: error -110 sending read/write command, response 0x0, card status 0x400b00
[    5.151349] end_request: I/O error, dev mmcblk0, sector 1
[    5.156796] mmcblk0: error -110 sending read/write command, response 0x0, card status 0x400b00
[    5.165438] end_request: I/O error, dev mmcblk0, sector 2
[    5.170913] mmcblk0: error -110 sending read/write command, response 0x0, card status 0x400b00
[    5.179525] end_request: I/O error, dev mmcblk0, sector 3
[    5.185002] mmcblk0: error -110 sending read/write command, response 0x0, card status 0x400b00
[    5.193648] end_request: I/O error, dev mmcblk0, sector 4
[    5.199096] mmcblk0: error -110 sending read/write command, response 0x0, card status 0x400b00
[    5.207737] end_request: I/O error, dev mmcblk0, sector 5
[    5.213216] mmcblk0: error -110 sending read/write command, response 0x0, card status 0x400b00
[    5.221868] end_request: I/O error, dev mmcblk0, sector 6
[    5.227330] mmcblk0: error -110 sending read/write command, response 0x0, card status 0x400b00
[    5.236128] end_request: I/O error, dev mmcblk0, sector 7
[    5.241530] Buffer I/O error on device mmcblk0, logical block 0
[    5.247643] mmcblk0: retrying using single block read
[    5.252983] mmcblk0: error -110 sending read/write command, response 0x0, card status 0x400b00
[    5.261667] end_request: I/O error, dev mmcblk0, sector 0
[    5.267155] mmcblk0: error -110 sending read/write command, response 0x0, card status 0x400b00
[    5.275843] end_request: I/O error, dev mmcblk0, sector 1
[    5.281343] mmcblk0: error -110 sending read/write command, response 0x0, card status 0x400b00
[    5.289988] end_request: I/O error, dev mmcblk0, sector 2
[    5.295577] scsi 0:0:0:0: Direct-Access     Multi    Flash Reader     1.00 PQ: 0 ANSI: 0
[    5.304184] mmcblk0: error -110 sending read/write command, response 0x0, card status 0x400b00
[    5.312872] end_request: I/O error, dev mmcblk0, sector 3
[    5.318357] mmcblk0: error -110 sending read/write command, response 0x0, card status 0x400b00
[    5.327041] end_request: I/O error, dev mmcblk0, sector 4
[    5.332563] mmcblk0: error -110 sending read/write command, response 0x0, card status 0x400b00
[    5.341249] end_request: I/O error, dev mmcblk0, sector 5
[    5.346723] mmcblk0: error -110 sending read/write command, response 0x0, card status 0x400b00
[    5.355416] end_request: I/O error, dev mmcblk0, sector 6
[    5.360924] mmcblk0: error -110 sending read/write command, response 0x0, card status 0x400b00
[    5.369570] end_request: I/O error, dev mmcblk0, sector 7
[    5.374967] Buffer I/O error on device mmcblk0, logical block 0
[    5.380979]  unable to read partition table
[    5.385803] sd 0:0:0:0: [sda] Attached SCSI removable disk
[    5.391564] sd 0:0:0:0: Attached scsi generic sg0 type 0


Friday, June 07, 2013

Fossil - Simple, high-reliability, distributed software configuration management 

A quick tutorial for myself on how to sync two fossil databases.

Putting some notes down on "paper" so I remember what I did for a personal project.  These directions would not be useful for a large project with multiple developers.
Along with being a distributed SCM, fossil is interesting because it is also a wiki and bug tracker.  It is also cross-platform, permissively licensed, self-contained, and doesn't require much in the way of complex installation or dependencies.

The quick start guide is good, although I wanted to write down my own condensed version.
http://www.fossil-scm.org/fossil/doc/trunk/www/quickstart.wiki

1. Download  here: http://www.fossil-scm.org

2. fossil init my-repo (or is it fossil new my-repo)
This creates a sqlite database named "my-repo", and spits out  the project-id, server-id, and admin-user username and randomly generated password.  You can write down this username/password combination, or set a new password in the next step.  By default, it uses the your current username as the admin user.  You can set this to something else when you create the repository by using the -A flag.

3. fossil ui my-repo
This will run the fossil web server and have it listen on http://127.0.0.1:8080/, and then launch your default web browser if it can.  When the web browser opens, you will be automatically logged in as the admin-user.  In this mode, it will not listen for connections over the network.  It will direct to you the config page so you can make changes.

4. User management and permissions
In the Admin, Users tool, you may want to limit what the "anonymous" group can do, as by default they can leave comments on pages.  I just unchecked everything for that group.

5. fossil server -port 8000 my-repo
This will run the server and bind to port 8000 and listen on all interfaces.

6. shut down fossil, and copy the sqlite database file over to another machine. start up the serve again.

7. fossil sync -R my-repo http://user:password@www.server.tld:8080

8. fossil sync -R my-repo
Later syncs seems to be fine with just that.






Thursday, January 31, 2013

Raspberri Pi and Motion Detection 

Taking inspiration from this Adafruit tutorial, I decided to play with a $10 motion detector I picked up at RadioShack and some python. My goal:  Don't play a sound when motion is detected. Instead, send my cell phone a text message.  This could be expanded to a variety of sensors.

Sending email can be a bit tricky from a home internet connection, as many internet service providers require that you use their outbound SMTP smarthost instead of sending email directly from your pi to the remote email address.  You will need to use the proper settings for your situation.  Also, if your cell phone number has an associated email to SMS service, check your cell phone contract to make sure you are not paying for incoming SMS messages.

Here is my first attempt, using wires and connectors salvaged from old computers, and some alligator clips to hold connections together.  The motion detector has a power pin, a ground pin, and a signal pin.  I connected the power pin on the motion detector to pin 2 (5v) on the pi, the ground to pin 6 (ground) on the pi, and the signal pin to pin 10 (GPIO 15).  Nothing started smoking, so all was well.






Here is the python script I used:
#!/usr/bin/env python
# This will write the date and time to a file when motion is detected.
# When motion is detected, it sleeps for a long time so we won't
# generate too much email. 

import time
from time import sleep
import smtplib

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)

motion_sensor_pin = 15

#Set up inputs
GPIO.setup(motion_sensor_pin, GPIO.IN)

localtime = time.asctime( time.localtime(time.time()) )

while True:
    motion = GPIO.input(motion_sensor_pin)

    if motion:
        localtime = time.asctime( time.localtime(time.time()) )
        print(localtime)
        with open ('motion.log', 'a') as f:
                 f.write (localtime)
                 f.write ('\n')
        sender = 'my@email.com'
        receivers = ['receiver@there.com']
        message = """From: Me Here <my@email.com>
        To: You <receiver@there.com>
        Subject: Intruder Alert

        Motion detected:
        """ + localtime
        try:
           smtpObj = smtplib.SMTP('your.isp.smart.host')
           smtpObj.sendmail(sender, receivers, message)        
           print "Successfully sent email"
        except SMTPException:
           print "Error: unable to send email"
        # If motion was detected, sleep for a while.   
        sleep(600)

    sleep(0.01)

I then cleaned up the wiring and adhered a small breadboard to the top of the Raspberry Pi case:

Thursday, January 17, 2013

Playing with Arduino - Esplora 

http://arduino.cc/en/Main/ArduinoBoardEsplora

Connecting the Arduino to a computer.

On the Arduino:
#include <Esplora.h>

void setup() {
  // Initialize serial:
  Serial.begin(9600);
}

void loop() {
  // read the sensor:
  if (Serial.available() > 0) {
    int inByte = Serial.read();
    int fahrenheit = Esplora.readTemperature(DEGREES_F);
    int celsius = Esplora.readTemperature(DEGREES_C);
    // do something depending on the character received. 
    switch (inByte) {
    case 'f':   
      Serial.print("Temperature is: ");
      Serial.print(fahrenheit);
      Serial.println(" degrees Fahrenheit.");
      break;
    case 'c':   
      Serial.print("Temperature is: ");
      Serial.print(celsius);
      Serial.println(" degrees Celsius.");
      break;
      }
    }
  }
Then write a python script (with the help of pyserial), and set the correct serial port.
#!/usr/bin/python
import serial

ser = serial.Serial('/dev/ttyACM0', 19200, timeout=1)
ser.write('f')
line = ser.readline()
print line
ser.close
When you call the python script (and have permission to that serial port), you get the temperature.

Sunday, July 29, 2012

Old story found 

I found a dot matrix printout of a story I wrote in perhaps high school.  I guess the best way to preserve it is to put it online, given that this piece of paper is the only record I have.

Untitled.

The old man turned away as the door opened.  Even though he was blind, he cringed as the bright light from outside poured in.

"I have a present for you" says the visitor, his dark eyes squinting to read the face of the old man who always seems to gravitate to the darkest corner of the room.

"I don't want your presents," mumbled the old man.  "I like my room the way it is.  Why do people always bring me new things, when they only confuse me?"  He reached out and took the parcel.  In it he felt the rounded shape of an egg, nestled in a bed of hay.  Perhaps it will be a song bird to keep me company, he thought.

The poor man, thinks the visitor, guilt forcing his eyes closed.  It is good he is blind.  He cannot see how disfigured he is.  "It is only me again.  I am sorry I did this to you," he whispers, and leaves.

"Again."  The word was like a voice in a cavern, each echo slightly different.  I am getting old, thought the old man.  I keep forgetting his name.

The visitor comes to see the old man again, and this time he is sleeping.  The nest sits on the table beside the bed, but the egg is split.  The small form wriggles out, looking so delicate.  "I am free," says the visitor.

The old man awoke, and checked the egg.  A smile appeared on his face as he felt the shards.  Tenderly he felt around the nest, and held the small creature in is hand.  It was not right.  As his hand closed to crush the newborn snake it bit into the flesh of his palm.

Wednesday, July 18, 2012

Adventures in hardware - Parallel Port and LEDs 

Goal: Blink some lights from the computer.

Parts: Computer with Parallel port and a cable. LEDs (From Radio Shack, 3VDC, 20mA).  Resistors, multimeter, and calculator.  Python and the parallel module from the pySerial sourceforge project.

Python: Makes this more simple than C for me.

On Debian, apt-get install python-parallel.
rmmod lp
modprobe ppdev
Add myself to the lp group to I can write to /dev/parport0

import sys
import parallel
s = int(sys.argv[1])
parPort = parallel.Parallel()
parPort.setData(s)

Electronics: Don't want to burn out the LED or the computer.
Pin 2 is first data pin, pin 3 is second, etc.  Pin 25 works as ground.
Using multimeter, discover 3.3 volts coming across the cable.
3.3 volts minus the 3 volts of drop from the LED leaves .3 volts.  How much resistor to get this down to 20mA? .3 divided by 20 = 0.015 k ohms or 15 ohms.  Smallest resistor I have is 100 ohms, but it works.
LED orientation is flat side to pin 25.

Use: Command line fun.
The python script might be called blink.py, and you need to treat the LEDs as binary.  I just call "./blink.py 1" to turn on the first pin. "./blink.py 2" to turn on the second, "./blink.py 3" to turn on both, "./blink.py 0" to turn them all off.

Armed with this setup and some Unix pipes, I can blink based on all kinds of events.  Yay!


This page is powered by Blogger. Isn't yours?