Raspberry Pi visual notification: mIRC and light chain

This is a real walk down memory lane: Scripting with mIRC! 10-15 years ago this would have been as awesome as air. Visual notification on activity in a chat channel. Nowadays there’s not much action on IRC, at least not where I’m hiding out..

The idea came when I got some very belated (5 months..) goods from Hongkong this week. Among other stuff a light chain/christmas lights. Five months ago my plan was to lighten up the dark Norwegian winter.. I had 20 min to spare and figured I should put them to use anyway.

I haven’t been scripting in mIRC for ages, had to dig up some old code from 2005. Back then I did a lot of stuff with mIRC. I even made a working IRC server at one point..

; LightNotify v0.1 for mIRC
; René 28.04.2014
on 1:text:*:#:{
  ; Something is said in any channel
  ; and mIRC window is not active notify me
  if (!$appactive) {
    notifyMe yes
  }
}

; 
alias notifyMe {
  if (($1 == yes)) {
    turnLight on
    .timerIsActive 0 5 isActive
  }
  elseif ($1 == no) { turnLight off }
}
alias isActive {
  if ($appactive) { notifyMe no | timerIsActive off }
}
alias turnLight {
  if (($1 == on) && (%lightison == 0)) { sockopen lightsocketON 192.168.1.50 80 }
  elseif (($1 == off) && (%lightison == 1)) { sockopen lightsocketOFF 192.168.1.50 80 }
}
on 1:sockopen:lightsocketON:{
  if ($sockerr) { echo -st Light notify: (socket: $+ $sockname $+ ): error: sockopen failed (too many requests?) }
  sockwrite -n $sockname GET /locallight.php?turnem=on HTTP/1.1
  sockwrite -n $sockname Host: im-name.net $+ $crlf $+ $crlf
}
on 1:sockopen:lightsocketOFF:{
  if ($sockerr) { echo -st Light notify: (socket: $+ $sockname $+ ): error: sockopen failed (too many requests?) }
  sockwrite -n $sockname GET /locallight.php?turnem=off HTTP/1.1
  sockwrite -n $sockname Host: im-name.net $+ $crlf $+ $crlf
}
on *:sockread:lightsocket*:{
  if ($sockerr > 0) { echo -st Light notify: (socket: $+ $sockname $+ ): error: sockread failed | goto w }
  else {
    var %count
    :nextread
    sockread %lightison 
    ;echo .. %lightison ;debug
    inc %count 1
    if (%count == 9) { goto w }
    goto nextread
  }
  :w
  echo -st Light notify: %lightison 
  sockclose $sockname
}

Basically, when someone talks in a channel, it checks if the mIRC program is in focus. If it isn’t it makes a http-call to a php-script (described here) on the RPi. Then it sends another call, to turns the lights off, when the program regains focus. Added some simple print notifications to the status window (echo -st ..).

It’s pretty much the same concept as the “Neighbor controlled christmas lights“, simple. But it was fun playing around with the mIRC syntax again.

Will I be using this? Well.. probably I will leave it on until the next project comes around.
Next project should be visual notification of the Facebook chat.. :P

The password: Changed it, forgot it – Raspberry Pi

Posted for my later reference.

It happened when I was about to connect the RPi to the interwebs. I changed the user password to something smart, then forgot it. Having not enabled the root user I was locked out.

As it turns out it’s really simple to reset. Just follow a simple step-by-step, like the one I found at rpi.tnet.com.

In short:

  1. Add init=/bin/sh to the end of cmdline.txt, which is to be found on the FAT-partition.
    Make sure the contents in this file stays in one line.
  2. Power up the RPi
  3. A command prompt magically appears
  4. Type the following:
mount -o remount,rw /
passwd pi
(enter a new password)
sync
exec /sbin/init

Remove the added command from cmdline.txt, power up the RPi and log in with the new password.

 

Neighbor controlled Christmas lights – Rasperry Pi

Even before getting the RPi I made some jokes about making it control my Christmas-lights. They are not the heaviest lights around; it is just 30 LED’s in a row running on 4.5v (three AA).

The easiest way to get started with the GPIO would be by connecting an LED. I followed this guide, and just connected the Christmas-lights instead. Pretty simple.

RPi GPIO Connected

The computer is now controlling something physical. How fun! :)
However, why stop there? Would it not be fun if my neighbors could control them too? I have the lights in my window so they are already visible for everyone.

I am of course not the first one with this thought, so there are a lot of tutorials and blogs about how to do this. However, that would ruin the fun!

My solution is the following: A PHP page allowing you to turn on or off by sending a get-parameter, and then returning the current state – are they on or off?

$what = $_GET['turnem'];
if ("on" == $what) {
	//turn on
	exec("gpio write 0 1 > /dev/null &");
}
else if ("off" == $what) {
	//turn off	
	exec("gpio write 0 0 > /dev/null &");
}
// get state
passthru ("gpio read 0", $gpio);

print $gpio;

Visiting https://thepi/?turnem=on would execute the command “gpio write 0 1” and not caring for any results, and then return the state. Visiting the page without any parameters would just return the state.

The command “gpio write” doesn’t return anything, so the “> /dev/null &” isn’t actually needed, but is good for further references. ;) Passthru allows for keeping any binary result from a command. In this case it will fill the variable $gpio with 1 or 0 depending whether the lights are on or off. Please note that this solution does require you to run “gpio mode 0 out” one time manually, which suits my needs.

Just having an empty page viewing a number isn’t very user friendly, but it allows you to make a fancy looking Norwegian page for your neighbors!

Yes, I know! A live web cam would be so much more fun..

Yes, I know! A live web cam would be so much more fun..

Bringebær i kortstokk

Jeg har gått til anskaffelse av en Raspberry Pi! =) Hva er nå det? Jo! Det er en minidatamaskin på størrelse med en kortstokk. Den er så og si like kraftig som den stasjonære PC’n jeg kjøpte meg da jeg var 15 år. 800 MHz, 512 MB RAM. Amazing!

RaspberryPi.

Raspberry Pi Model B. Bilde: Wikipedia.

Den kommer uten innkapsling. Så i påvente av bedre tider at Adafruit skal få inn denne, Adafruit Pi Box type blank, så måtte jeg finne noe annet å putte bringebæret i.

Behold the Raspberry Pi in a deck of cards:

Raspberry Pi i kortstokk

Raspberry Pi i kortstokk: Det praktiske fremfor det estetiske.

Raspberry Pi i kortstokk 2

Raspberry Pi i kortstokk

Tenker det er på sin plass å nevne at jeg ikke har mer forhold til nettbuss enn at de ga meg denne kortstokken en gang..  :P

Kortstokkesken gjør nytten sin. Mindre støv, og ikke minst mindre muligheter for å ta på noe man ikke bør ta på.. Jeg har ikke lagd noen ekstra luftehull. Esken holder en temperatur på ~40 °C, når CPU’en yter 100% og holder ~58-62 °C. Det bør være OK.

Akkurat nå tjener den som multimediasenter. Så får man se hva morsomt man kan prøve ut senere i år! :D