📜 ⬆️ ⬇️

Ethernet lamp for continuous integration and not only

image Hi to all habra users! Not so long ago, the Amperk project was launched. The interest was noticeable, so we continue to grow. And this is our first post in the corporate blog.

Today I want to share the experience of creating a gadget based on Arduino, which can be useful for you. And if it does not prove to be useful, I hope that some moments of work on the device will be interesting.

This gadget is a lamp that glows in different colors depending on the messages going to it over the local network. Why do you need it? Personally, as a member of a team of four programmers, this thing is necessary for indicating the operation of the Continuous Integration server. The server, of course, is able to send notifications to the e-mail and jabber when the assembly fails, but this is boring and not convenient: there is no way to look somewhere and instantly understand what is happening with the project: everything is in order, everything is bad or right now it is going assembly.
')
The problem is not new. I read several times how people became izgolya, screwing a traffic light, lava-lamp and usb-flasher to the computer. I wanted to do something simple that can be brought to the office, stuck in the hub and that's it! And so that it works without a tambourine. Well, let's try!

We will need Arduino, an Ethernet Shield for it, a flawed lamp from Leroy-Merlin, three LED strips of different colors, a handful of small things and a supply of patience.

The device should work without settings, immediately, scooping information from the ethernet hub. Thinking over how best to do this, I decided: let the lamp just get its IP via DHCP, and then listen to a certain port and catch UDP packets that tell it the color that needs to be lit. What they said last, and so we shine. And who will send them there, the lamp does not concern. If you do this, then the gadget can be used for anything, not just for the CI server.

Prototype


Let the device listen to port 7190, and catch packets of the form: "4 bytes of the header, 1 byte - any for future needs, 3 bytes of RGB color." And if the signal is not 30 seconds, let it glow white: so it will be possible to understand that something is wrong.

Sit down to write firmware. And then the first disappointment: the standard library for Arduino does not provide either DHCP or UDP. But Arduino they would not have been if it were not for the community. The necessary developments from enthusiasts were found quite quickly ( DHCP , UDP ). I will not clutter the code with this post. All the source code of the firmware miracle lamp is open on Bitbucket . Here and the firmware itself and related utilities, which will be discussed below. If you're just wondering what the code looks like, start digging from the main app.cpp file. With basic knowledge of C ++, the code should be clear.

To quickly test whether the lamp understands network packets, let's make a small script that would accept the color from the command line, which needs to be broadcast and broadcast it, say, every second. Mmmm ... but what IP will be given to the lamp? You can, of course, be confused and implement some kind of discovery service to search for ethernet lamps on the network, but it seems to me that this is a brute force. Then I remembered that there is a wonderful
IP broadcast stuff. The essence is this: if you send a packet to IP 192.168.1. 255 , it will be heard by all devices with an IP of the form 192.168.1.xxx.
The result is such a script .

With software figured out, take up the hardware. In the firmware, for managing the colors, outputs 7, 8, 9 are involved and it is assumed that red, green and white colors will be used. We assemble this scheme:

image

Stitch Arduino. Nothing works! We fix, flash, try. We fix, flash, try. And so many times until the firmware code becomes debugged and does what is required of it. Success!

image

The photo shows a situation when packets are sent over the network with a request to glow red and green.

More light


For the prototype used low-power 5mm LEDs. Weakly for a geek lamp. But the LED tape for outdoor advertising - the thing that you need. But there is a small problem. It is assumed that 12 V will be fed to the tape, and Arduno can only issue 5 on their paws.
They are not enough even to somehow set fire to the tape. If Arduino is powered by a separate power supply, not by USB, it is possible to feed from 7.5 to 12 V. This voltage then passes through the voltage regulator on Arduino itself to become 5 V, but before that the voltage can be picked up from the Vin contact.

Solved. We will feed Vin to the tapes, and block / allow the current flow using transistors:

image

Turn on! Drum roll ... Bar! Not lit! Ethernet shield, Arduino with its lights blink, and the tapes are silent. I called the whole scheme: everything seems to be working. But no. Long danced around to about, but without result. Leaving the entire structure connected, went to make tea. And what was my surprise when I returned, I saw that the white ribbon is glowing. Thus, the device reported that the IP address was received, there is a connection, just a UDP command has not yet existed. Fine! We send the command to turn on red. Drum roll ... again the bar! How was white and stayed.

After repeating the experiment a couple of times, I suspected that the Ethernet Shield did not have enough power. Yes, that is right. If, in addition to the external 12V power supply, connect a USB, then everything works.

image

A couple of hours trying to understand why I retreated this way and decided to continue: well, let USB be turned on. The gadget is stationary, “for itself”, and besides, there remains a loophole through which the microcontroller can be accessed without disassembling the lamp.

Leaving the device to work for a long time, I noticed that the voltage regulator on the Arduino warmed up decently. You can't hold a finger for a long time. Since I want the lamp to work around the clock, for every fireman, with the help of hot melt, I attached a small radiator to it

image

Packaging


All this design now needs to be placed in the case. For this, I bought an ordinary lamp from an incomprehensible soft material, similar to pieces of dense polyethylene glued together. So, gut-lamp: get all the native stuffing and send it to the trash

image

Along with breadboard, putting the whole thing inside the lamp was problematic. It is not reliable. Therefore, we transfer the entire circuit from the breadboard to the circuit board. As a board, Proto Shield is quite suitable. Solder the legs, install transistors, solder wires. We call the received fee to make sure that there is contact where it is necessary, and where it is not needed there is no. It seems to be all right. Putting design together. It turns out such a sandwich:

image

We cross fingers, we include. Works!

Now all the giblets must be placed inside the cube. To make the glow more uniform, I confused the LED strips into a ball, fixed them with plastic clips, and stuffed a crumpled translucent plastic bag inside the cube. For the cover, it was decided to use a square piece
cardboard. Arduino is attached to it with double sided tape.

image

Gently close the lid and fix it on the 4 screws that previously held the lamp’s native filling

image

Integration with Team City


We use this system as a CI server. Now you need to make sure that the necessary events send IP packets clear to the lamp via IP-broadcast server. It would be good to write a Java plugin for Team City. I will probably write it in the end. But now, not to
spend time exploring the API, use the quick'n'dirty way: let there be a script that once every X seconds looks at the web page of the Team City report and by it understand what state everything is in.

The source code of the script is in the same place, next to the firmware. If you have Hudson, CruiseControl, whatever, you can use a similar approach.

dress rehearsal


We create an intimate setting for our lamp, we make a simple project in Team City, we cross our fingers, turn on everything and freeze with a feeling of complete satisfaction:

image
image
image
image

What happened and did not work



It turned out to solve the problem: we have a lamp that shows the state of the project now.

In addition, the thing turned out to be quite independent and, if desired, it can notify about different things: the level of traffic jams, the performance of a website, the presence of unread letters, etc.

It was not possible to make a very simple device. There are already three wires sticking out of the lamp. USB is clearly superfluous, but it was not possible to solve the power problem. Yes, and the food itself, perhaps too much. After all, there is the PoE technology (Power over Ethernet). If you make more effort, it seems to me you can do
so that only the twisted pair patch cord is sticking out of the lamp.

Theme with USB-powered does not give me rest. Perhaps someone from habraexpert can explain this behavior? I will tell you in advance what I tried to do to get around it:



None of this helped. It is known that Arduino himself uses no more than 50 mA; Ethernet Shield - 150 mA; one tape at 12 V - 45 mA. Any opinions?

And in general, how is your gadget?

UPD : Now a person has written to the e-mail of the store who apparently incorrectly wrote his return address - I cannot answer him, but he wrote the following:

and the current-limiting resistors in the base of the transistors are not forgotten ??? Without them, you can arduino and burn ... Well, their absence can definitely be the cause of the increased current consumption, but you have shorted the legs of the port almost to the ground with transistor bases.

And he is right! And is it just as soon as I missed it? I thought that if there are resistors in the tape itself - everything is OK, but they are not on that part of the circuit. Thank you, kind man!

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


All Articles