 Ladies and gentlemen, nothing like building up a bit of tension for an afternoon demonstration. Thank you so much for your patience with any demonstration, and particularly I've discovered with the Internet of Things, it doesn't all go as planned. Welcome this afternoon to Drupal Raspberry Pi and Alcohol. Yes, there will be alcohol, but I do ask you to drink responsibly. My name's Mark Corbyn, I work with Acquia as a support engineer. I've been there for just over two years. I've been playing with Drupals since Drupal 5, and now I'm trying to get into Drupal 8. Look more at Drupal 8, obviously, with things coming in for that. I've also, I just wanted to say, this project that I'm about to show you started, I've been involved with the robotics club at the local school. And most of the robotics that the kids have been doing there has been with Lego Mindstorm. But some of them are quite aware of Arduino and Raspberry Pi. Their focus at the moment is on that sort of stuff, but with the intent to lead on to others. So the project that I'm demonstrating this afternoon started with that. So the little picture there is, it's not the best picture, but it's a little dog light. And what I set up, and it was just to show the kids what other things you can do with things like Raspberry Pi. It's a light, it's basically got a relay connected to a Pi and a motion detector. And basically to demonstrate, not only did the light come on, but it could make sounds and things like that. So the kids were very excited when we saw that. So that's the genesis of the project I'm going to show you this afternoon. What this is this afternoon is it's about combining Drupal, Raspberry Pi, Node.js and Arduino. I'm assuming, probably incorrectly, that most of you in this room know or are aware of those things. But please, if you want some clarification, speak up and we can do it as we go along. And most importantly, I think, which is why you're here, alcohol will be involved. The reason I mention that is there is, well actually, I think, yes, let's get straight into the demonstration. For this, ladies and gentlemen, I do have some props. Quickly, let's just go, would anyone like a beer? I'm looking for a volunteer, so your hand was up first. Who would you like to come forward to? So what I've got, could you pick a beer of your choice? And I'm hoping that they're Twistop, otherwise I may have a handy dandy bottle opener. Is it Twistop? Champion. Champion. Okay, would you like to pour yourself a glass, please? No, no, not pretty shit. Sorry, and what's your name? Gold. Could we give Gold a round of applause, please? Okay, oh. Looking at the head, that's the man who likes his beer. Gold, let me introduce you. Now, it's a little known fact that once Darth Vader passed away, and I do apologise for the height difficulties, but once Darth Vader passed away, it's a little known fact that he was actually converted into an alcohol breathalyzer. So what I've got here at the moment is Darth with a breathalyzer. Now, again, Murphy's Law, his eyes are lit up, but usually the lights will be off until there's alcohol detected. I'm suspecting there's either a wiring problem or I've had one of my props. One of my props was this, and I think the smell of the paint has actually been triggering stuff as well. So what I'm going to do, Gold, is I'm just going to set up a web page, and I'm anticipating that this won't work because I've been rushed into getting this going. Let me just test this bit, and then we should be right. I do apologise, ladies and gents. Gold, if you would like to take a sip or two of your beer, now, that would be fantastic. No, no, no, no, no. Oh, you're a scientist. You're sending you control. I like that. No, due to his time restrictions. Yeah, and Murphy's Law, I'm now not able to load the page. OK, here we go. Wow, that's slower than I had hoped. OK, so what I'll do is I'll just get you, the intent is that you take a sip and you blow on Darth's mouth. Now, I don't know, and I don't know if his eyes are going to light up more. So if you'd like to do the honours, please. No, write in, write in, get close into his mouth, into that grate. And I think you'll find, did we see that get brighter? No, I'm hoping, I'm hoping. The intent is that the lights should get brighter, depending on the level of alcohol. Thank you, Gold. You can actually take that beer as well. That's to say thank you very much. So that's the intent. The other intent, and I'm just going to... So what I've basically got, and let me... Yeah, let's go with that. Excuse me, could you do this, Anna, and hold that for me while I speak into it? So, ladies and gentlemen, what we've got here is a setup whereby I've got an alcohol sensor and I've got two LEDs. So this is the alcohol sensor, and that's basically stuck in the middle of Darth's mouth. His eyes are made up of what looks like eggs, but they're actually LEDs. And these LEDs, as I said there, are controlled by the voltage, so the higher the voltage input, the brighter that they are. If you like, I'll pass those around, and I do trust you, Drupal, is that they'll come back. Essentially, the sensors, thank you. That's the sensors, and they're connected to an Arduino. They're not connected to a Raspberry Pi. And I'll explain why. Cool, all right, so we've done the demo. There we go. So this is the setup that we've got. Here's your two sensors, or three sensors, I should say, the two LEDs and the alcohol sensor. They're connected to an Arduino. The Arduino is connected to the Raspberry Pi, and then we're talking essentially through the browser and through Drupal and through Apache, which we'll get to, to make that all happen when it works correctly. So what I really wanted to do this afternoon is to just step you through each of those components and how they fit it together and why. So this is the first step in the project that I had to get working. The alcohol sensor, and I'm just gonna assume that the other sensors are there, is connected to an Arduino, connected to this thing called an I2C bus, which is an integrated to integrated bus. Essentially, it's a way that integrated circuit boards can talk to each other. The reason that I chose an Arduino over directly connecting it to the Raspberry Pi is that the output of the alcohol sensor is an analog output. So the Raspberry Pi will only take a digital signal. So that's 3.3 volts of a digital signal that we can only feed into that. Whereas we've got an analog here, the output of the sensor, and the Arduino will nicely take, this will actually take digital or analog, but for the purpose of this project, I'm feeding it as an analog. So the idea is basically I can get these two talking, detecting the alcohol and detect the level of voltage. And that will do that quite happily, and I could do that just with an Arduino program running on that. So the trick then was to go, how do I connect the Arduino to the Raspberry Pi? So again, yeah, I won't go through the programming for that, only because I've run out of time. But essentially, and again, if you're not very familiar with the Arduino, there's Arduino.cc, I would go to that website. It's pretty fantastic to explain about the Arduino, and more importantly, there's a free download to actually program it. So what you do is you write a program, which is essentially a loop to talk to, in this case, the analog signals to get those out and you'll talk to it over USB bus, a USB, yeah, USB link. So what we've done so far is we've connected up the sensors, and we've connected that to an Arduino. We've programmed the Arduino. I guess the other thing I didn't mention is that that Arduino is set up to ping every couple of milliseconds to say, is there any change? Is there any change? Or actually it says, give me the value that you're reading off the sensor. Give me the value that you're reading off the sensor. What we then do is feed this over to the ITC bus, which is essentially going into the Raspberry Pi. Now, as I went through this project, I was stuck with the problem of, I've got Drupal, which we all know and love, Apache, and I've got this thing here called an ITC bus. How the hell do I get those to talk to each other? So what I've discovered is this thing called Node.js, which I know the younger developers in this are probably right onto. This was a bit of a revelation for me, but essentially what we're doing is using Node.js as a server to essentially ping the Arduino, which is essentially pinging the alcohol sensor, and then we're gonna feed that to Drupal and see that on the page. So just quickly for those that aren't aware of, familiar with Node.js, it's in a C, asynchronous event JavaScript runtime. So it's essentially JavaScript, but it's triggered by events. So we're used to events such as click on a mouse, right click, left click, enter keys being pressed, things like that. All those get triggered and essentially will run a function through Node.js. Now, the other thing that I've found with Node.js is that there's this thing called Node.js package manager. So we're probably very familiar with the package management for Ubuntu or Red Hat package manager, so you're managing the applications there. This is essentially the same thing, but it's for Node.js applications. I'll come back to that. Yeah, okay, let me come back to that. So what we've essentially got, as I said, is a Node.js server, which is talking to the ITC bus to say, what have you got? But it's also talking to Drupal. So there were two things that I needed to set up to get this thing going. I had the server side for Node.js, which was basically getting the information essentially from the alcohol sensor, and then it was feeding it to Drupal to show the messages, and that's what I'll show you later. So what we're going to look at now is just a quick run through of the configuration for the Node.js server. The other thing to be aware of is that there's a package, so I mentioned before about NPM, Node.js package manager. There's a package that has been written called Drupal Node.js. That is a package that runs the server. And I'll just go back to this to say, when you have any of these packages, they will always have a thing called an app.js, so that's essentially your application that's running. To execute that, you use a command Node, and already we're confused because we're so used to Node in Drupal being associated with content. This is nothing, this is an actual executable that we run, and the argument that we give it is the app name, in this case app.js. You can also, so this will run, and depending on your application, this will run an app and finish. With this, there's another one called a forever command. That's essentially to run it as a server, so it will keep running this literally forever until you kill that process. So that's the two differences to be aware of with the Node.js stuff. So as I mentioned before, with the Node.js server, now we've got this thing called Drupal-Node.js. How do we install it? So Node.js, being a package manager, will actually let you install this node. So in this case, so the general thing is npm install module, and that will create, it always creates a node modules directory. And then under that directory will be, will be the packages, the Node.js packages that you wanna use. The beautiful thing is that not only will it install the package that you need, it'll actually pull in the other ones to add those in. One of the important packages that I use, well, essentially the Node.js Drupal module uses, is this thing called Socket.io. And that's essentially how I'm communicating from the Raspberry Pi through to the Drupal, ah, through to Drupal. So this is just a bit more detailed to explain. This is where it gets put, under Drupal-Node.js, and your files are in there, and your app.js is essentially running under there. And again, that's just to run it, and that'll run that server. Okay, what I might do is just show you, quickly, a configuration file. So, when we get the server, there's a couple of things that we need to configure. You need to configure a host, you need to configure the service key, and what's referred to as the backend. And that's essentially how you're speaking to Drupal with that. So let me just quickly get a configuration file to give you an idea. So, as you can see, is that readable, or is it too small? Three, four, three, two, one, here we go. There's your page now. All right, actually that's big enough. So, as you can see, this is literally just running under the home directory for the Raspberry Pi. So, because it's a server, we can run it from anywhere. I've just chosen to run it from, in this case, projects, Drupal-Node.js Pi, Node.js servers, Drupal-Sanpit. And this is where we see this node modules. So that means that I've used NPM install to install node, and that's the particular module that it's running. And if we just quickly look here in that directory, you can see that there's the app.js, this configuration file that I'm about to show you. And this will be the node modules, or the modules that NPM has installed that are needed by this particular module, Drupal-Node, to run. So if we have a look at Node.js.config, I didn't realize how hard it was to manipulate the keyboard whilst you're holding a microphone. Okay, so there's essentially two sections. So we've got the settings here. We can set the scheme, so it can be HTTP or HTTPS. The port that we're running on, we're just putting the server on 8080. The host, you can restrict it to one host. If it's left null, then you're basically letting any server access it. The important thing to sync this up with Drupal is to put in a service key. So I've just chosen a random service key there. The other section here is the backend. So that's essentially how is it configured for Drupal itself. So Drupal is running on port 80. It's the local host, so they're running on the same server. The scheme is the same. And the other important bit is the base path. So Drupal 7, which I don't know if you saw when I ran that from the browser. That's where it's currently running from. So just up here, I've got slash Drupal 7 for that. So that's essentially the configuration on the server side. Okay, cool. Okay, so we've configured our server. And that means that we can talk from Node.js to Drupal. The other bit, though, is I've got this alcohol sensor. How do I get that information into Drupal? So what this node module allows us to do is add these things because extensions. So I've got an extension here, alcoholDetector.extension. That's essentially written in Node.js. And that is basically what goes and pings the Raspberry Pi to say, give me the information about the alcohol sensor. Now, I've got it set up so that every two seconds it says, give me the value of the alcohol sensor. Give me the value of the alcohol sensor. And then that will display that on the screen if it's above a certain threshold. So yeah, that's just a bit more visual about those extensions. So you can put any number of extensions in to work. So they're essentially still running under that server, almost like mini modules, if you like. Okay, so we've spoken about the alcohol sensor. We've spoken about Arduino. We've got it to the Raspberry Pi. We've got this thing called a Drupal Node server running. Node.js server. Now, what do we do in Drupal? So in Drupal, the Node.js module consists of three main modules that you can use to communicate. So there's the integration module. There's a configuration module and the notifications module. So let me just show you that in under admin. So I've obviously enabled a couple of others, but here's our Node.js config, our integration. So you can see that's grayed out, which means that's dependent. The others depend on that. And we've got notifications. This essentially lets you configure the Node.js server settings. And this will have the way to talk to the server in it. So let me just show you that configuration. Would anyone else like another beer while they're waiting? Okay, so we can go into configuration here. And you can see there that that's a similar layout to when we looked in that configuration file. So we can define our protocol. Now, this server host is actually incorrect. I'm just gonna correct that now. And we've also got, this is the port that we're gonna talk to the Node.js server on. So let me just change that. Actually, one more thing. Before I change that, what you can do, the other beautiful thing that Node.js has is, if you go to admin report status, it's actually got a line to say, am I connecting to the Node.js? So in this case, it's not. If I change that configuration, we should see that. And if we refresh the admin page, there we go. So you see now, this is saying that Drupal is actually talking to the Node.js server. And what you're seeing there, which is what I was hoping it would work at the beginning. These are messages that pops up. I'm not sure how readable that is from the back, but it's basically saying alcohol detected with a number, I can smell it on your breath. What that is doing is basically getting that information from the alcohol sensor, feeding that through the Raspberry Pi, feeding that to the Drupal Node.js server, and then Drupal itself is seeing that. Now, where that's happening is essentially in the, there's that notifications module. Let me show you here. So what I really wanted to show you was, this is what's called the notification module. It's job in life is literally to take what's happening from any message that's sent from the Node.js server and display it as a black pop-up, like you saw that, in Drupal. What's happening, and this is probably the important bit, is that we're setting up this thing called a JGrowl, which is literally does the pop-up for us. So that's a little piece of JavaScript that pops up those messages. So because we've added that in, we can then go to our JavaScript where that's referencing, and that will actually detect the message from the Node.js server, and then display that as a message. So let me just show you that. So you can see here, we've got a dot, oh, sorry, we've got a dot JGrowl with a message and a header, and how long to display that for. So that's the JGrowl popping the message up. The important bit in relation to the Node.js server is that we've got this callback here. So essentially what's happening is, you've got a callback set up in Drupal, and that receives that from the Node.js server to say, if I get this particular callback, and remember when I talked about events at the beginning, that Node.js is event-driven, that is essentially looking for that event. If a message is sent from the Node.js server, then it will trigger that callback, and then display those messages at the beginning. Messages from the alcohol sensor, sorry. That's essentially it. Yeah, are there any questions? No, that was Drupal 7? Yeah, that's right, yeah. Yeah, that was, yeah, and that's probably what didn't quite make clear. If I go back to that slide, yeah, literally here. So you had Node.js server, and then your Drupal modules here. Yes, yeah, yeah, yeah. What I probably didn't make clear is there's essentially a message bus being set up between the two. And yeah, so essentially this knows to look for messages from this, yeah. So I didn't hear the first bit. Yes? Yeah, yeah, I haven't gone down that aspect. Yeah, I'd probably have to look at that more. Yeah, I suspect it won't be too easily. I mean, look, in one regard, to get this stuff working was a challenge. Documentation-wise, some of the stuff was a little bit old. What do you mean by that? Oh, I actually don't know, to tell you the truth, I apologize. Yeah, yeah, yeah. Yeah, yeah, no, I don't know, sorry, yeah. Thank you very much. If there's no other questions, ladies and gentlemen, thank you very much for your attention.