A USB email indicator

A USB email indicator

One of the common issues linked to internet consists in knowing whether you've got mail at a glance, without consulting any computer-like equipment. This week, we provide a solution to this issue by lighting a Yocto-PowerColor when an unread email is awaiting your attention in your mail box. In fact, the real difficulty lies in integrating the Yocto-PowerColor in a decorative element, making the result visually pleasing.


You probably have certainly already seen these lamps made of optical fibers. The idea is to modify one to make it change its color depending on events, such as an incoming email.

Ok, it's kitsch, but what if we drove it by USB?
Ok, it's kitsch, but what if we drove it by USB?



We found one of these lamps for less than 10 Swiss Francs in a shop where they sell cheap electronic gadgets. We played with it during three minutes, and then, obviously, we took it apart. Inside, there is only the bare minimum: three batteries, four leds, four resistances.

We payed CHF 9.90 for it, and it's not worth more
We payed CHF 9.90 for it, and it's not worth more



In short, there is largely enough space in the lampstand to install a Yocto-PowerColor as long as you separate the led from the command part. We constructed an acrylic glass frame to place the led at the ideal location within the lamp, but you can use materials easier to work with, such as plywood. Make sure to cut some vents to allow some air in to cool the led.

If you split the led from the command part, it should fit
If you split the led from the command part, it should fit


For better light rendering, we placed a Led-Engine optics on the led. The result is rather conclusive.

The original electronics
The original electronics


The Yoctopuce version
The Yoctopuce version


On the wiring side, we connected the command part to the led with a Picoflex wire, and we simply cut a standard USB cable which we soldered directly on the module using the pads designed for this.

A little bit more ...
A little bit more ...



... impressive that the original
... impressive that the original



When the lamp works, we then need to code the part which checks whether we've got mail in our inbox. We are going to do this in C# because it seems to be the language which is the most used among Yoctopuce module owners.

In fact, the programming part is very simple: We use the excellent ImapX library which enables us to reduce the "check mail" part to a series of calls. Updating the led requires only two lines of code.

Here is the code of the main function of the application. It connects itself to the mail server, counts the number of unread emails, then searches an RGB led with the logical name MailIndicator, and switches it to red if there are unread emails, to green otherwise.

private void checkForNewMail()
     {

      log("Checking...");

      // connect to the mail server, you might need to tweak the parameters
      // to make it work on your own mail server
      ImapX.ImapClient client = new ImapX.ImapClient(server.Text, 143, false);

      bool result = false;
      result = client.Connection();

      if (!result)
      { log("Connection failed");
        return ;
      }

      log("Connected");

      // logon
      result = client.LogIn(username.Text, password.Text);

      if (!result)
      { log("Login failed");
        return  ;
      }

      log("Login ok");

      // retreive messages
      ImapX.MessageCollection messages = client.Folders["INBOX"].Messages;

      log(messages.Count+" mails found in inbox");

      // count unread messages
      int UnreadMessages = 0;
      for (int i = 0; i < messages.Count; i++)
      { messages[i].ProcessFlags();
        if (!messages[i].Flags.Contains(ImapFlags.SEEN))  UnreadMessages++;
      }

      log(UnreadMessages + " unread messages");
      client.LogOut();

      // update the led status, We look for a led with logical name
      // set to "MailIndicator" (the function  name, not the
      // Module name)
      YColorLed led = YColorLed.FindColorLed("MailIndicator");
      if (led.isOnline())
        led.rgbMove(UnreadMessages > 0 ? 0xFF0000 : 0x00FF00, 1000);
      else
        log("No 'MailIndicator' led found");
    }



Notice that this function works with a Yocto-Color as well. You can download the full project here.




Add a comment No comment yet Back to blog












Yoctopuce, get your stuff connected.