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