PCDuino power

So yeah like the title says, the PCDuino seems to crave power when running a 2.5″ SATA hard drive. When using a SATA drive you need a 2.5AMP power supply, MINIMUM, or you will experience issues with the hard drive shutting down and disconnecting. With the PCDuino by itself a 2amp and 2.4amp supply seems to be ok. I was using an Apple iPad charger rated at 2.4amps, I use it on the Pies all the time with no issues, although I have read that others have some problems with them shutting down after a while (can’t find the link right now). I moved from the iPad charger to my Orico USB power supply (rated at 2.4amps each plug). It worked here ok but after 20 minutes the same issue appeared. So I pulled out the wall wart power supply that came with my CanaKit. Its a 2.5amp power supply that shipped with my RPi2. This power supply has been working flawlessly.

I tried two different 2.5″ drives with all of the power supplies I mentioned. One drive says 0.55amps the other 0.45amps both at 5v of course. They would both power up but after about 10-15 minutes the drives would start clicking, like they were losing power and cycling over again. Access to the drives was also lost while this happened. I tried three power supplies that were all rated 2.4-2.5amps. It seems they are not all created equal…

I need to get my hands on a USB current meter.

Side note: I purchased a BananaPi SATA hard drive cable kit off of Amazon for like $3. It will work – but you must SWITCH THE POWER AND GROUND CABLES! The BananaPi swaps the 5v and GND on the power cable. Just pull the pins out and switch them and it will work just fine. Or get a cable for the PCDuino or I head the Cubbieboard cable works too.

Server Death

I lost the server. The motherboard decided to depart from this world while I was out of town the last few days (this post was written a good week or so after the actual event). Good news is that I did not lose any data or hard drives, just the server. It’s probably going to take me a minute to acquire a new server, I can’t just get a new motherboard. I was using an old Dell XPS 710 that apparently uses special BTX connectors so no replacing anything. It was old anyways. I do see two swollen capacitors so I may try to bring her back, we shall see.

UPDATE: I did swap out the two swollen caps that I saw but it changed nothing, the board still did not boot.

I need to backup my DB a little more often it seems, I was only able to go back to October. “Lost” two months of data. I say “lost” because it’s not really gone it just needs to be retrieved from the (working) drives.

I happen to have a few Raspberry Pies and a PCDuino Nano sitting here on the desk so I commissioned the RPiv2 to be the new temporary server until I can get my hands on a new one. The Cisco E1200 that I had as an emergency backup router is in place so the house has network access again and the Pi should be able to handle Apache and OpenVPN for a while. Sadly I have lost all my custom firewalls and other roll-your-own-server/router goodies. Back to being a “network civilian” again, shitty.

You wouldn’t believe the story behind this server anyways. When I got the machine it had been stored in a barn for a few years. It had about 1″ of crud inside it that I had to clean out and it had apparently been in contact with water as there was evidence of such. I removed the sound card as it looked damaged by water and other crap. But to my surprise after a cleaning it fired up. After a bit of testing it was decided that it ran fine so I moved it into production – and gave away my old (loud as fsck!) AMD Phenom… doh! Turns out three months later that was a bad idea. Two days ago I found out this Dell had once been sitting on the bottom of a pool. Whoa wtf!?

RPI Jessie and Ping

I was having some issues the other day with SD Card corruption, just after a few hours use and a few reboots the card was done. So I opened ApplePi-Baker and got ready to re-flash the card. Then I thought it had been a while so I went to see if there was a new distro, I don’t really keep up. In fact yes there was, Jessie was now available. Sweet.

So far I have not really noticed any issues (other than this one) with Jessie. It even has Node-RED out of the box. But I couldn’t figure out why my presence detection flow wasn’t working. It was working just fine before I switched from Wheezy to Jessie and yes I did install the Ping node required. I could ping my phone so what was up? I decided to try and ping my phone from the RPi. AHA! That was the problem.

Trying to run a ping resulted in ping: icmp open socket: Operation not permitted

Say wuh? Some quick Googling and I found this thread at the Ubuntu forums.

Run command ls -l `which ping`. If it does not look like this -rwsr-xr-x 1 root root 30856 2007-07-06 02:40 /bin/ping then that is why. The important part is the “s”.

-rwsr-xr-x 1 root root 30856 2007-07-06 02:40 /bin/ping

If you don’t have an “s” run this command to fix it: sudo chmod u+s `which ping`. You should be able to ping away to your hearts content now.

Node-RED: Presence Detection

Presence Detection

Huge thanks out to Martin Harizanov (https://harizanov.com) I don’t know the man but sifting through his very informative blog has allowed me to get this code (and many others) up and running. You can find his original post on the subject here https://harizanov.com/2014/03/presence-detection-using-phones-wifi-and-node-red/

This is basically his work with a few tweaks. I decided to send all my sensor logs to my home servers MySQL db. The RPi uses an SDCard that has limited write life, and I think there are some performance issues there too (I don’t know, never bothered to look it up, I’m talking out my ass). I have a home server that runs MySQL and Apache so I was going to just offload that work away from the RPi anyway.

To get the presence detecting done I ping for my phone every 30 seconds or so then that result goes to a function to get analyzed (by Mr. Harizanov’s code), then that result is given to another function that UPDATES a MySQL database then finally on to a MySQL node to make the connection.

Ping -> Analyze Ping Function -> Update MySQL Function -> Connect to MySQL Server

I noticed that it took about 2-4 ping results before it would change status, and that it didn’t matter if it was a 30 second or 5 minute delay. So I went with 30 seconds, it doesn’t hammer the Pi too bad and I don’t have to wait too long to test it, hah. I did not thoroughly test this theory, I just noticed it once or twice so I could be way off.

Hopefully this helps someone else in their time of need. One is glad to be of service.

Presence Detection

If you DO NOT have or use a cellphone (or a device that uses WiFi that goes with you everywhere) then this WILL NOT WORK for you.

It works by utilizing the fact that almost everyone has a cellphone and that they usually always have it with them. The idea is simple, Node-RED looks for your cellphone. If it can see your phone it assumes you are home along with it. How do we see your phone? Ping it. Basically ping the IP address of your phone every so often and it the ping comes back you are home, if it times out you are assumed away.

You will need node-red-node-ping installed for this to work.
(http://flows.nodered.org/node/node-red-node-ping)

Nodes Required

  • Ping Node http://flows.nodered.org/node/node-red-node-ping
  • Function (Analyze ping results)
  • Function (Insert data payload into MySQL db)
  • MySQL Node to make the connection http://flows.nodered.org/node/node-red-node-mysql

You may want to add a debug node after the Update DB function and two inject nodes before the Update DB function, set as 1 and 0 to simulate your phone home/away.

Ping Node
This one is simple, just add the IP of your cellphone and set the timer. I used 30 seconds, although I will probably change this to 5 minutes. It helps to have control over your router so you can set static IPs.

Function Node (Analyze Ping Result)
Don’t forget the global variable, this is needed in the next step.

Function (Update MySQL db)
You will need to change the db settings to match yours of course

Connect to MySQL node
This is pretty straight forward, setup with your servers credentials

That should get your Node-RED to detect if you are home or not based off your cellphones Wifi. Pretty cool, yeah but what do you do with that info? Log it? Display? Yes! Take the info from my last post and apply it here and we can check the status any time we want! http://itsalllost.com/node-red-requesting-sensor-data-via-http/

Check status via HTTP

Here’s the code to check the status of the global variables (make sure they all match!)

Here is the flow for presence detection in all it’s glory!

Node-RED: Requesting sensor data via HTTP

Fo as cool and useful as Node-RED is I am surprised at the lack of “useful” documentation and examples on the web. Sure http://flows.nodered.org/ has some very useful flows and nodes, no doubt but they don’t really help a beginner slap some IoT goodness together. I have some knowledge but I by all means don’t have “skills”, at least I don’t think so. Anyway enough rambling on to the code…

Screen Shot 2015-11-17 at 10.36.29 PM

DISCLAIMER: I by no means really know what I am doing, I know just enough to be dangerous. I am not responsible for what you do or what happens, by you or someone following anything mentioned on this page (or site).

 

Display sensor data on a webpage with Node-RED
This should allow you to take data from a sensor or another node and display it on a webpage.

Nodes you will need:

  • HTTP request (set as GET)
  • Function (Get current values)
  • Template (HTTP)
  • HTTP Response

Get Current Values Function

HTTP Template

That is the bulk of it, now all you have to do is declare the global variables you just created. Add a function block directly after your sensor (or edit the one you already have). Now you just need to set the sensors payload to equal the global variable.

Set each global variable for each sensor you have like this (I added it at the very bottom, before “return msg;”.):
context.global.variable1 = msg.payload;

Refresh the page button

This should allow you to get a button on a webpage to refresh the page for you.

Nodes you will need:

  • HTTP request (set as GET)
  • Function (Return to page)

Return to page Function:
msg.res.redirect("/checksensors");

Well thats it, I hope this was enough straight forward code and enough direction to get you going. I had to scrape this all together. One is glad to be of service.

For your pleasure and in the chances I may help cure some headaches, because I hate headaches, here is all the code (minus setting the global variables):

This post is were I found the code needed to get the above results:
https://groups.google.com/forum/#!searchin/node-red/gpio/node-red/ycho_15kJvM/bTOY9tbwrmYJ