📜 ⬆️ ⬇️

Notification of unread incoming letter using Yoctupuce-Demo

image

Introduction:


I was inspired by 2 articles, this one and this one . I really liked the idea of ​​the first article, but I thought that buying an Arduino for this idea would be too “fat”. Then, when I stumbled upon a second article, I realized that Yoctopuce-demo is just what I need! And I decided to order it.


Package:


After 25 days, I received an envelope from Switzerland in the mail. It contained the chip itself, packed in an antistatic bag with the name and date of production. There was also a cable and a letter with instructions. The chip was 2x2 cm in size, it had 2 LEDs, and one button. Unfortunately, you can only interact with the 1m LED, but that's enough for us. The device worked without drivers, but you had to download VirtualHub, which is available for all platforms on the manufacturer’s website. It weighs only 170 kb. A detailed review of the chips is here , so I will not describe it in detail.
image
')

Selection of programming language:


On the manufacturer's website you can download libraries to the following languages: Javascript, PHP, C ++, C #, .NET, Delphi. My choice immediately fell on Javascript. And here's why: it is extremely clear and simple to develop, runs directly from the browser and does not require installation. Moreover, it is cross-platform, which is important. Included with the library is a folder with examples for all devices. Here is pastebin.com/atweug6J sample code for Yoctopuce-Demo. In this example, the program checks if the device is connected every 0.5 seconds. There are 2 buttons (On / Off LED).

What's next:


Next, I had a problem: How to check for unread emails? Javascript cannot connect via POP or IMAP itself and check their availability. But there was a way out. Gmail has a feed at: mail.google.com/mail/feed/atom . At this address, we will be issued unread messages. You only need to be logged in to Gmail in your browser. We look at the source code and find the line X, where X is the number of unread messages. This is what we need! It remains only to count this number. And this is done very simply:

if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","https://mail.google.com/mail/feed/atom",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;

fullcount=
xmlDoc.getElementsByTagName("fullcount")[0].childNodes[0].nodeValue;


It remains only to slightly change the source code of the example that came with the libraries and the trick is done. Let's use the ready-made refresh function, adding to it the load of the fullcount variable. Next, compare fullcount with 0, and depending on this, turn on or off the light bulb. You can also increase the time between updates. To do this, simply change the value of setTimeout from 500 to 5000. That's it. Checking works!
image

Update: With
module = yFindModule(serial);
module.set_beacon(true);

You can turn on / off the flashing blue LED.
image

Why is this convenient?


You will ask this question. I already have an email client that immediately after receiving the message will inform me, why should I make an external device? Everything is very simple. For example, you are watching a movie, or playing a game and you receive a letter (Any application with fullscreen). You will not notice your email client alerts, but you will always notice a green light bulb.

Conclusion:


It turned out a small handy script. About the pros, I have already said. I found only one minus - you need to be logged in to gmail in the browser. The script is not perfect, a lot of things can be improved and added. If you have any ideas - write in the comments. I will be glad to feedback.

References:


Full script code: pastebin.com/VwVFeghW - corrected link
Manufacturer website: www.yoctopuce.com

Source: https://habr.com/ru/post/140345/


All Articles