Tag Archives: coding

Powershell Script for emailing PPCoin price on Vircurex

I have recently found myself checking the price of PPCoin on a daily basis. Obviously this sort of thing can be automated with a script, so here it is. Powershell was brought into service for this one: I haven’t got much experience with Powershell so had to google my way around, and learnt something in the process.

The Powershell Script

$url = "https://vircurex.com/api/get_info_for_currency.xml"
$xml = [xml](new-object system.net.webclient).downloadstring($url)
$from = "***@***.com"
$to = "***@***.com"
$subject = "PPC"
$server = "servername"
$smtp=new-object Net.Mail.SmtpClient($server)
$smtp.Send($from, $to, $subject,$xml.hash.PPC.BTC."highest-bid".get_InnerXml())

Obviously you’ll need to set the from and to addresses, and the servername correctly for your environment. Also, as I am using this on a domain joined PC, it uses the default credentials so I didn’t need to set any on the SmtpClient. I’m sure the above script could be improved so that you pass the to address in via an argument, but this is a quick and dirty hack so it doesn’t really matter. However, it definitely would benefit from some exception handling…

Scheduling the Script

I then saved this script and scheduled in Windows using the Task Scheduler. I had to use the full path of the 32-bit Powershell executable (C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe on my Windows 7 box), and used -Command “D:\PPC.ps1”  for the arguments (where D:\PPC.ps1 is the full path of the script):

Powershell Scheduled Task

And there you go! Powershell to the rescue.

As a sidenote, I have had issues sending emails when using the SmtpClient in .NET and a domain-joined PC & user. If you’re getting a ‘Client does not have permissions to send as this sender‘ exception, then you need to ensure that the user ‘NT AUTHORITY\SELF’ has ‘Send-as’ permissions on the user in question. The following link helped me out with this issue:

http://social.technet.microsoft.com/Forums/exchange/en-US/e763de97-88a1-494d-9841-4f3a466b5604/exchange-550-571-client-does-not-have-permissions-to-send-as-this-sender

 

Brainwave: Bluetooth Receiver and Android App

Brainwave Toy: The Mindflex

Having been interested in meditation, consciousness modification and the quantification and monitoring of self performance, the following webpage posted on Hack-a-day caught my attention:

http://frontiernerds.com/brain-hack

After looking at the options, we decided that hacking a toy EEG would be the cheapest / fastest way to get the data we wanted. Here’s how we did it.

A toy EEG? Interesting. Very interesting. The toy of which they speak is the Mindflex, and you can find the web page for this particular toy here:

http://mindflexgames.com/what_is_mindflex.php

with a bit more info here:

http://company.neurosky.com/products/mattel-mindflex/

The Mindflex uses Neurosky technology to read brainwaves. Here’s a quick excerpt from the website:

Utilizing NeuroSky’s advanced ThinkGear™ technology, Mindflex™ reads your brainwave activity with a wireless headset.  Concentrate…and the ball rises on a cushion of air! Relax…and the ball descends. It’s literally mind over matter!

Brainwave Mindflex Toy
What the Mindflex toy looks like. That’s not me, by the way

I managed to pick a Mindflex up for about £50 from Amazon here (plus I had a £25 gift certificate lying around, so managed to justify the price quite nicely, cheers!).

The guys over at frontiernerds grabbed the data from the Mindflex headset’s serial pins using an Arduino. After some success with this approach, I decided to test a more elegant solution. This experimentation was also born out of a desire to minimise the (already small) risk of electrocution that had so carefully been pointed out on the frontiernerds website.

Getting the data out

I found some bluetooth to serial modules on the dealextreme website – you can see them here. Fortunately these modules work with a 3.3v supply, so was able to power it straight from the headset’s power supply. I fired up a quick project in Visual Studio and tested the data stream from the headset, and it appeared to work! Unfortunately my port of the Arduino Brain Library to .NET didn’t work quite as expected.

So, the next stage of the project is an Android application to read data from the Mindflex (and optionally, a bluetooth enabled heart-rate monitor) and log the appropriate power bands to a local database, provide some nice charts and optionally log the data in real time to a remote server. I have started the coding already, and you can find the project here:

https://code.google.com/p/bt-wave/

Swyx Server: Retrieving a list of phonebook entries using VB.NET

Swyx Server Phonebook Entries

You can use VB.NET to obtain a list of phonebook entries from Swyx Server. You’ll need these Imports:

Imports SWConfigDataClientLib
Imports SWConfigDataClientLib.Proxies.IppbxServer

And this is how you do it:

Using lm As New LibManager
With lm
.BaseProtocol = SProxyObject.BaseProtocol.TCP
.AuthenticationMode = SProxyObject.AuthenticationMode.Trusted
.WSBaseUrl = serverName
End With
Dim ePb = lm.GetUserPhoneBookEnum
Dim phoneBook = ePb.GetPBXPhoneBook("%", True, True)
 
For Each r As Proxies.UserPhoneBook.PBXPhoneBookEntry In phoneBook
Trace.WriteLine(r.Name + " " + r.Number + " ")
ePb.FreeForReuse()
Next
 
End Using

For more information about Swyx telephony, check out the following link:

http://www.swyx.com/