For all your music news related needs


Week 7:

IoT (Internet of Things) is a term which is becoming commonplace to the general public as its usage has grown exponentially in recent years. IoT refers to the networking and connecting of all devices to the internet. This can mean printers, lights, fridges, and even mattresses

Week seven brought on the task of an IoT sub-project. The task to be completed over the following three weeks involves using sensors on an Electric Imp device in order to gather and display data, this data is then to be passed to a database to later be viewed on devices with web browsers such as mobiles and desktops. Setting this up involved making use of the ElectricImp app in order to “blink-up” in order get the electric imp online which in turn would allow it to connect it to the electric imp site and grab a requested codebase to run.

The Electric Imp IDE (integrated development environment) is designed for development in Squirrel. Squirrel is a high level imperative object-orientated programming language which is designed to be lightweight, making it ideal for Electric Imp development. Squirrel has many similarities to languages such as Java, C++, JavaScript, and Python making it very easy to pick up if developers have prior knowledge in any of these languages.

In the Electric Imp testing environment provided, issues arose which made internet connection to the Imp very sparse which in turn slowed down progress dramatically however within this time period a system was devised which allowed a user to enable/disable an LED on the electric imp via the use of a website. With this system there is three separate areas of involvement; the code on the device, the agent code, and the webpage for the user to control.

Agent Code:

// define the http handler
function requestHandler(request, response) {

local state = request.query["state"].tointeger();
device.send("led", state);
response.send(200, "OK");
}
// register the http handler
http.onrequest(requestHandler);


Device Code:

// define led to be the pin in question
led5 <- hardware.pin5 ;

// configure the pins as digital output pins
led5.configure(DIGITAL_OUT);

// function to turn LED on or off
function setLed(state) {
led5.write(state) ;
server.log("Light : " + state);
}
// register a handler for "led" messages from the agent
agent.on("led", setLed);

Webpage HTML:

<a href=”https://agent.electricimp.com/3e254a3a?state=1”>Switch on</a>
<a href=”https://agent.electricimp.com/3e254a3a?state=0”>Switch off</a>

Within the above example, a user would access the HTML webpage which would have two hyperlinks on it, “on”, and “off” when pressing on these hyperlinks, there’s a get request send with “state” equaling either 1 or 0. The agent gets this request, decides what to do with it, and then requests that the device code runs a specified function (in this case turning the light either on or off. As you can see in the device code, we can gather a log of what is happening with the line of code: server.log();

Further tasks which were incompletable due to hardware and time limitations included making use of the light sensor and voltage reader in order to gather additional data in the server.log();. This would have been completed using hardware.voltage(); and hardware.lightlevel(); then printing them to the server log.

word count: 429