EW Project 3: Development

To to begin development on this project we needed to sort out how we'd measure the content on the bins. One of the ideas was to use the ultrasound distance sensors on the lids to see how high the bins had piled up. However Mike mentioned to us that another group were already using this. Feeling the way to go was weight we asked Mike if DAT had any weight sensors. Alas not. Mike did say DAT had some force sensors though. These were similar to the ones we'd used for Coffee.

It was interesting to work our the pressure sensors. I wired them up and they looked something like this:

Once this was wired up I used the serial connection to monitor the values coming from each. Unfortunately the force sensitive resistors were both reading different values, with one of them having total inconsistency and acting rather sporadically. After bashing my head against this, rewiring and rewriting the code and getting nowhere I enlisted the help of one of my housemates, Simon - a robotics student. He suggested I use different analog ports. This worked flawlessly and after kicking myself I got on with developing it further.

Jamie picked up some kit from Poundland, including some small bins, perfect for our project. The bins were really inconsistent with the sensors and didn't read very well. After playing around a little I discovered the sensors only work effectively with pressure on a fixed area in the middle of the sensor. So to combat this I stuck some boardpins on the underside of the bins to act as legs and distribute the pressure among those legs.

This worked fairly effectively and we had reliable readings coming from the bins. Putting weights in the bins in the form of beer bottles proved the system worked and the score/ratio reading was pretty good. The next step was to connect it to the web service. Jamie designed the following logo and webapp for the system:

The webapp was a PHP based system that accept values via a secret URL with a GET value. Once this URL is accessed it sends the value in the GET to the SQL database. The the webapp has a script running that pulls the value off the database every half second. Just to note the Coca Cola reference(s) is/are from one of our realtime projects, where we went slightly overboard. The next step was to get the Arduino connected to the webapp. Initially we were just going to get the Arduino to send an HTTP request directly to the webapp. However this was really unreliable and didn't really work more than around 4-6 times, the same problem we encountered with ELDR. Because the technology we were introduced to was Node Red for this project we decided to give that a go. Using MQTT we connected the Arduino to Chris Hunt's broker. We set up a Node Red instance and subscribed it to the MQTT broker topic that our Arduino was sending data to every two seconds. 

We got Node Red receiving the data, however getting it to send to the database proved to be tricky. Jamie downloaded a MySQL node for Node Red. However this didn't really work over the web. The server where the database was hosted kept rejecting the connection. A lot of troubleshooting later and the situation hadn't improved. I tried using Javascript's built in XMLrequest stuff, but Node Red's function node didn't appear to support it. There was an HTTP request node that I tried using too, but unfortunately it didn't support passing variables. 

The problem was that the HTTP request node supported everything I wanted it to except the one issue with passing the msg.payload data into the URL before sending the request. Taking this as a personal challenge I decided to try and write my own Node Red node. I began scouring the folder structure and the source files for each node and discovered that each node was actually fairly readable and easy enough to edit. I began hacking away at the HTTP request node to try and add in the payload functionality. I got a little bit of the way there before I decided to check the node list again to see whether or not there was something else I could use. Lord behold as I scrolled right to the bottom of the list I discovered a HTTP GET node hidden away in the 'advanced' section of the list. I could have punched myself as this is exactly what we needed. I halted development on my custom node and plugged this one in instead. Surprisingly it worked flawlessly without issue! I was over the moon. The system was finally complete.


Popular posts from this blog

Logitech G502 Proteus Core Teardown & Scroll Wheel Replacement

Turning a laptop screen into an external monitor.

Letter basket: Productive procrastination