Saturday, February 14, 2015

Auto hot dater for Singles Appreciation Day (SAD)

Out of luck, out of love, but definitely not out of job! On this fateful day (14feb15), yours truly come to realized one by one the brethren have left to join the dark side. Rather unfortunately, there is still one last man standing, holding the ground resisting the "social norms" to sign on the dotted line.

In certain parts of the world with chinese populations 光棍节 (guang1 kun2 jie1) aka singles day is celebrated every 11november (11.11) of the year. However, in the other part of the world, it seems to yours truly singles are not celebrated. Yours truly celebrate Singles Appreciation Day aka S.A.D on 14Feb by making auto hot dater powered by arduino!!

So, how do singles mingle??? What are the laws of attraction between male and female humans? What are the grounds two humans decided to stay together and till death do us part?? These are questions yours truly ponder upon but yet to have answers to them. Until recently, one of the "bro"was acquainted with a girl via dating apps on social media (tinder, paktor, and so many more. Yeah, he is a trawler). Quickly they become an item and subject to much gossip; which unfortunately yours truly is in the party and have to GIGO (Garbage In Garbage Out). Having heard the experience of him using dating apps, perhaps there is a way to quantify how human hookup. The biggest face palm moment is when "bro" mentioned he "swiped right" at every single female profile.

From the above conversation, yours truly assumed other parameters such as profile picture on dating app, human attributes are held equal and have formulated some hypotheses. These hypotheses are: male have to swipe right more often [1] and be less selective of the female profiles [2] in hope of getting a higher count of "matched" (both male and female swiped right at the other's profile);  a set of preferred female pictures of the said male subject can be trained into a mathematical model, then feed into image recognition system via openCV where test data is acquired from the dating app's female profile picture; automated decision making is done within openCV and then instruction to swipe left or right is achieved with an arduino.

To answer the above hypotheses, an experiment has to be setup. The following parts needed are part1 of the experiments: swiping left or right using arduino with random 50-50 chance, and increased swiping frequency per hour in hope for a higher count of "matched".

parts list
1. Arduino (an uno is used here)
2. Regular servo motor
3. smart phone with a stylus (note3 is used out of convenience) or without a stylus.
3a. Stylus can be made by referring to this URL
4. dating app of choice (tinder is used out of popularity with "bro")
5. jig to hold the smart phone, and servo with stylus. (a 3D printed PCB vice is inverted out of convenience)

Step1: stylus and servo

1. assemble the stylus on the "zero" position of the servo motor. Servo will be moving from 0 to 90deg, or 0 to -90deg
2. an apparatus to hold the stylus. Being cheap, yours truly have used some blue-tac, but the effect is not good. Will elaborate more at observation.

Step2: Arduino programming
0. pin7 of arduino is wired to the servo.
1. random 50-50 to swipe left or right.
2. servo to rotate L or R depending on the random value 0 or 1
code here: 

Step3: Setting up the jig
1. align the smartphone with the stylus on servo contraption at the apex of the servo rotation.

The final setup is in the following picture

Step4: Enjoy!

The cheapo contraption of stylus on servo needs a rework, e.g with a L-R clicker type of setup. If the alignment for the current setup is not aligned properly or out of the way as observed from the video above, it will swipe left irregardless of the random value calculated within the program.

Final Note: Ego might be dented, but NO humans are harmed in this setup. The profile on dating apps are fictitious, and deleted after this experiment.

Thursday, February 5, 2015

setting up IoT server with ThingSpeak on Ubuntu 12.04

installing IoT server with thingspeak on ubuntu 12.04.

some time back yours truly has did some IoT inspired device, by streaming temperature sensor data using ESP8266 to the Internet; the receiving side of the sensor data is the FREE ThingSpeak server, courtesy of iobridge. details of the IoT streaming data setup here

The ability to display IoT sensor data in a chart on the Internet is extremely useful. The following screenshot depicts the "public view" of my thingspeak sensor data chart that can be shared on web presence eg a blog or website; data collected can be used for processing/detecting/predicting. Note the LHS of the chart as compared to the "pattern" on the RHS. analyzing outliers, yummsss.

The free thingspeak server allows for sensor update once very 15sec per channel ref here: ; in other words, if a sensor (or many sensors) is required to send data at shorter interval eg every second, the free thingspeak server is not able to accommodate. thanks to open source software by iobridge, humans now can install thingspeak on their own computing resources, and customize according to their requirements.

picture above depict thingspeak server running off a VM on my "server" behind a simple network in my office. It is not publicly accessible.

picture above depict thingspeak server running off a VM on the R&D cloud in T931 behind a myriad of ACLs. It is not publicly accessible.

The step by step guide from the source repo is available here

The major software components needed on ubuntu 12.04 to use with thingspeak are mysql, ruby, rails, and major pkg updates. Assuming the server is behind a simple network with only a router-to-internet, setting up thingspeak is a breeze. There are open source bash scripts, eg to help to manage the installation, originated from this blog post Don't you just love open source software??

The complexity comes when 
1. installing on a VM that sits in the cloud that is behind a myriad of ACLs
2. scaling up the thingspeak server in the cloud as a PAAS, and clustering the resources.

your truly had his fair share of frustrating after office hours trying to fix some of the installation issues due to the complexity of the network and also the unfamiliarity with ruby, gems, and rails (first time installing it). nonetheless, the main gripe is documented in the gist below which address BADSIG from apt-get update, git to use https, gpgkeys: HTTP fetch error 7: couldn't connect: Network is unreachable, packages cannot be authenticated!, etc.

the screenshot of thingspeak server is running

the expanded installation bash from the user mentioned above is available here

now, let's start to do some IoT inspired stuff by streaming some data to thingspeak

Wednesday, February 4, 2015

3D printer with Cloud computing for one touch 3D printing over the cloud

3D printer with Cloud computing for one touch 3D printing over the cloud

Some time back, yours truly wrote about how to prepare a rep rap 3D printer for 3D printing over the cloud computing infrastructure. the  details of cloudify the rep rap 3D printer url here:

"The process to 3D print a 3D model can be quite an obstacle, i.e need to have physical access to the 3D printer and a SD card handy, power hog, heat emission, UFP emission. What if we can remotely send a 3D model (in *.STL) to be 3D printed on a 3D printer and also observe the 3D printing process over the Internet? Definitely it is going to be convenient as everything can be done at the fingertips; godsend piece of technology for those can’t wait for the 3D printers to be locked down in a facility equipped with exhaust and medical grade filter that is capable of filtering Ultra Fine Particles (UFP) in the range of 100 nanomether that is much finer than PM2.5. The purpose of this article is to share a step by step guide of setting up 3D printer to print remotely."

The process mentioned in the earlier post of using octoprint and slic3r is still not transparent to the end user details here:
user still have to process the gcode and submit it via octoprint.

 thanks to the good work rendered by FEW cloud FYP members Fahadh, Ehan, Wei quan, now we can 3D print over the cloud with a single click. Check out the youtube video. For best effect, please choose HD for video settings.

Friday, January 16, 2015

[IoT] streaming temperature data acquired with DS18B20 to thingspeak using ESP8266 on Arduino Mega

IoT streaming temperature data acquired with DS18B20 to thingspeak using ESP8266 on Arduino Mega

Streaming data to internet could not have been easier with the release of ESP8266.
Gone are the days of using a concoction of software, permanently tether a microcontroller based temperature sensor to a computer for it's internet connecting capability, and visualizing the data. back in 2012, yours truly have dabbled in such complex setup of hardware and software URL: for the purpose of demonstrating IoT and of course to stream the office's temperature to the internet . the sole purpose is to make an informed choice of coming to office or not on the weekends, based on the reading of the temperature data.

If you wonder what is ESP8266, check out previous post  ESP8266 is a very low cost WiFi upgrade to "Internet Enable" any microcontroller based systems that are able to speak serial with it. It is retailing for S$9.5 here or ~USD5 on friendly website of middle kingdom. Earlier, A C&C (command & control) type of application is created with ESP8266 allowing appliances to be controlled from the Internet. This round, let's explore uplink type of application; to stream real and live data to the internet. The IoT data store of choice is thingspeak for the fact that it is easy to register for an account, clear and concise documentation, and any microcontroller based system can be setup to stream data to in in practically no time.

Your truly is no stranger to sensor for the purpose of temperature data acquisition. The matter of fact, expensive sensor does matter Obviously, the weapon of choice in this application will be the trusty DS18B20 temperature probe, or it's variant. Setting up DS18B20 can be slightly tedious as compared to LM35, but it is well worth the effort. As far as my DIY sous vide  setup is concerned, DS18B20 temperature sensor served it's purpose.

If you can't wait to make it yourself and want to jump straight into the visualization of the temperature in the office from the internet, follow this URL

iframe of the channel is here:

Parts needed for this uplink IoT setup
1. Arduino Mega
2. ESP8266
3. DS18B20 temperature sensor

please refer to the previous posts mentioned earlier on hooking up the ESP8266 with Arduino Mega, and DS18B20 temperature sensor.

Once every partss are wired accordingly and dandy, the final outcome should look somewhat similar to the following.


Go to the thingspeak website to register for an account. it is FREE!!!!
Once registration is done, navigate to the following to acquire the API key.
This API key will allow ESP8266 and Arduino Mega to send data to thingspeak server.

program arduino mega with the code that is available at the footer.
then observe from the serial monitor whether data has been sent successfully. On the thingspeak channel of yours, a simple graph is available to visualize the data received via IoT.

there are several cool features on thingspeak, such as public view and private view of streaming data; data can be downloaded in CSV for later manipulations.

the following is the said temperature sensor data from the office, streamed to thingspeak using ESP8266 and Arduino Mega since 31dec14.

can you spot the trend of the visualization and make some sense out of it?
code here: 

Thursday, January 1, 2015

Internet controlled AC Appliances with ESP8266

Internet controlled AC Appliances with ESP8266

ESP8266 is a very low cost WiFi transceiver that can be added to any existing microcontroller based setups via UART (serial link) to enable the system to communicate over the Internet via WiFI. In this guide, the objective is to achieve the epitome of IoT inspired setup; that is to control an AC (Alternate Current) electrical appliance over the Internet using ESP8266. The outcome of this setup: a command to be sent from a website through the WiFi network to ESP8266 with Arduino Mega to turn on an AC lamp for 2 seconds. The AC lamp is a place holder for any electrical device to be "Internet Enabled".

The following diagram describes the necessary parts and setup for this apparatus. On the left is an Multiplug modified with SSR, In the middle is Arduino Mega. On the breadboard is ESP8266 and sparkfun logic level shifter. Arduino Mega Pin7 is for SSR, Serial2 pin16,17 for UART with ESP8266, and Serial0 for USB serial monitor.

An IoT controlled AC appliance can be quite daunting to construct. Setting up such apparatus requires cross domains knowledge such as computer networking, electrical, electronics, programming, administering software on the Operating Systems (linux) of a server (or just another computer), and the often unspoken (and hair pulling moments) troubleshooting techniques. Combining several key building blocks to this setup can be overwhelming. Not to worry, because the divide and conquer approach can be adopted to R&D (Replicate & Duplicate) this setup. Which has been conveniently divided, constructed, and described in the following sections. It is highly recommended to construct the building blocks/modules and tested for functionality, prior to assembling this apparatus.

The necessary building blocks/modules of this setup is broken down into the following
1. Computer Networking: Setting up a WiFi Access Point/Router. Setup wifi security, either OPEN, WEP or WPA. DHCP for the connecting clients (the computer and ESP8266). PING-ing the devices on the network. DMZ for TCP server (if necessary, use for Internet side to access)

2. Electrical  & Electronics: Setting up the IoT inspired SSR Multiplug, and setting up ESP8266 with Arduino Mega; connecting the SSR Multiplug to ESP8266 with Arduino Mega

3. Programming (software): Firmware for ESP8266 on Arduino Mega to control the SSR Multiplug upon receiving a command. Server side software for sending a packet (that contains the command) from a TCP server through TCP/IP  to the ESP8266 port 8266.

4. Administering OS (linux): install the necessary software packages Tornado, Python, and Pip.

5. Testing/Troubleshooting

the following diagram describes the apparatus getting ready to be tested.

The following video describes the operation of clicking on the website to send a command via WiFi to ESP8266 with Arduino Mega to turn on the AC lamp for 2 seconds.

Computer Networking
Parts needed: WiFi Router
Note: ESP8266 defaults to IP address of 192.168.1.XYZ out of the box. Both the ESP9266 with Arduino Mega and the server will connect to this WiFi Router network of 192.168.1.XYZ/24. Ensure that firewall rules are removed temporarily or a permit all are applied during testing.

1. setup WiFi Router to issue IP Address via DHCP using the IP address pool 192.168.1.XYZ; subnetmask set to /24 e.g With the router available on hand, it is configured to allocate IP address in the range of to 99 to PC. Just a matter of personal preference.
2. setup WiFi security, OPEN, WEP, or WPA. Current setup on existing WiFi Access Point/Router. For the sale of simplicity during testing, OPEN can be configured. For long term usage, it is recommended to configure for WPA.
3. Configuration on different brands of WiFi Router might be slightly different from one and another. RTFM.
Alternative: Modify the settings in ESP8266 to suit the network address on the existing WiFi Router network.

Electrical & Electronics
Parts needed: IoT inspired Multiplug modified with SSR; ESP8266 connected to Arduino Mega.

Th details steps of modifying a multiplug with SSR is available on instructables or here

The details steps of connecting an ESP8266 to Arduino Mega is available on instructables or here

once these two building blocks are ready, connect pin7 of arduino mega with the signal pin of the SSR. VCC on the SSR to 5V on arduino and GND to GND on arduino. Ensure all components are connected to the common ground.

Software (Programming)
There are 2 pieces of software necessary for setting up this apparatus. One, the firmware that is residing in the Arduino Mega with ESP8266 and controlling the SSR in the multiplug, and the other is the software residing in the linux server to send a "command" via a website.

The firmware deals with the necessary parameters of ESP8266 to connect to a WiFi network, and waits for the "command" from the server via TCP port 8266. The port number is a deliberate choice, but it is not recommended to choose ports that are in the "well known" e.g ports number < 1024. Choose ports that are in the ephemeral ports region if it pleases you. The "command" is a keyword sent by the server side software, e.g "LED".  Upon receiving this keyword by the ESP8266 and Arduino Mega, pin7 is held high for 2 seconds and then held low for testing purposes. The "command" is a variable that can be customized. Out of convenience, and also the discovery of the LEDServer software on github, the keyword "LED" is used.

The server side software is obtained from github out of convenience for testing. Many thanks! Please follow the URL below for a detailed descriptions on the static html page and python. Every time the button send is pressed, the string "LED, R, G, B" is sent to ESP8266. Essentially, only the "send" button and the keyworkd "LED" are used by this setup in particular. The original intention of this server side software is to use the variable R, G, B that is of type integer measuring from 0-255 for setting the colour of neopixel.

Alternatively, and for the sake of simplifying the server side software for testing there is an opensource tool sockettester v3.0 can be used. URL here 
The ESP8266 LED Server software is used as an example for the sake of complicity of the explanations of this IoT setup.

code for firmware here:

code for server software on linux here

Administering OS
Since the chosen server side software mentioned earlier runs off linux; there are several pre-requisite steps needed. In this setup, a virtual machine running ubuntu 14.04 desktop is assumed, and a USB WiFi adapter is connected to this virtual machine. The server side software requires python, Tornado webserver that can be installed via pip.

1. Configure USB WiFi adapter to connect to the WiFi router. This step varies, depending on the WiFi security setup such as OPEN, WEP or WPA.

Existing WiFi network is using WPA, so it has to be set up accordingly.

apt-get install wpasupplicant wireless-tools

nano /etc/network/interfaces

#add in the following ssid and wpa password
auto wlan0
iface wlan0 inet dhcp
wpa-ssid ______
wpa-psk _______


2. install pip (if it is not installed)
sudo apt-get install python-pip

3. install tornado (if it is not installed)
pip install tornado

4. execute the server side software as per the instructions in github. The following diagram describes this operation.


check IP address of the devices from WiFi Router's management console, and ping the devices. The following screenshot describes this operation.

Test ESP8266 for functionality using AT commands.
The following diagram describes the commands used for testing.

Savour the moment