Wednesday, March 5, 2014

How to use the Arduino watchdog to build a reliable IOT WiFi prototype



Problem


Arduino is a convenient but unstable prototyping/DIY platform. When building applications that are supposed to run indefinitely (for example, monitoring), you will need a fault tolerance approach that virtually guarantees that your mote can self-heal.


Solution (ok, it's a hack!)


Use the a call to the set the hardware watchdog. Usually this is used to handle short processes (milliseconds). Locally the Arduino exposes a few time intervals including a gargantuan 5sec timeout. As it turns out, this is extremely useful if you do not quite your Wi-Fi shield like, oh I do not know, the CC3000.


So how does it work? Well you can find out more here (no point in reinventing the wheel) but basically you wanto import the library and then use a pattern like:

...
wdt_enable(WDTO_2S);
critical section here
wdt_reset();
...



The first call tells the watchdog to bump the board (hardware reset) after the specified interval, in this case 2 seconds. The second call after the critical section put the watchdog back to sleep so you can continue your logic and avoid the draconian and unnecessary reboot since your critical section returned succesfully.

I used this on the CC3000 since this board can occasionally take a very long time to return from DHCP and/or DNS resolution. At times, it won't actually return at all thus the need to hack the Arduino code to self heal. Obviously the solution would be to dig into the CC3000 open source code and find out what is causing the application to hang indefinitely but who has that much time while prototyping? ;-)

Restoring Ms Elly

Ms Elly is a 1972 vintage Moto Guzzi. A 850 Eldorado to be precise, thus the name Ms Elly!
I decided to give her her own blog so look for it here.

Thursday, November 21, 2013

Linode NodeBalancer and SSL/HTTPS, nodes are DOWN

This is a short post that might help others since the Linode documentation is unclear on this one.

Problem

Load balance SSL APIs (HTTPS web servers) running on several Linodes using NodeBalancer. You followed the directions from here and added your Linodes to the NodeBalancer but they wont go UP.

Solution

The NodeBalancer needs to talk to your nodes over HTTP. So once you create your configuration for HTTPS, add the nodes and use port 80. That is, if you want to add node 198.1.2.3 (yes, you should only use internal IPs), you want to add it as 198.1.2.3:80

Tip

If your experience problems and one of the node does not want to go UP, delete it and start over. I had this problem after changing which port to use etc. and I could not figure out why it would not work. So I deleted it and created a new entry for the NodeBalancer. Also, give it a minute (literally).

Thursday, September 26, 2013

iOS7 and the status bar overlay problem

If you are porting an iOS app to iOS7 you have run into this problem. Not to give away the ending but the solution is provided to you by Apple in the Interface Builder. Yep, it is that easy.

Problem

in iOS7 the status bar overlays with your views at all times. This is a new behavior, in previous releases the status bar had its own real estate and it was not sharing it. An example of the problem from our app dog stories, in stores soon ;-)
our app in iOS6

our app in iOS7 prior to fixing it

Solution

  1. in IB, select the File inspector
  2. go to view as and switch to iOS6
  3. select all elements in the view that you want to move when the app is run on iOS7, that is, select all UI object like buttons, tables etc. that you need to adapt. In our case above, we wanted the camera button, the pull down, the search button and the table to all move down 20 points if the app is running on iOS7
  4. switch to the Layout inspector
  5. under iOS6/7 delta, put 20 in the deltaY 
    1. if needed, like in our case for the table, we also subtracted -20 from the delta height
  6.  go back to (1) and switch back to iOS7 and rejoice, you are done
Update: iOS7 will by default try to slide UITableViews from under the header/footers by adding about 30pts, so your first cell will look like it is starting lower than it should. Read this post to learn how to remove that annoying blank header on top of you table! http://stackoverflow.com/questions/18388429/uitableview-is-starting-with-an-offset-in-ios7

our app in iOS7 with the element shifted down by 20 pts and the table height re-sized to -20pts

Monday, July 15, 2013

Before picture

Repacking a stuffing box (packing gland)


Vessel: 1979 Newport 30MKII
Engine: Universal Diesel 18hp (5216?)
Gearbox: 2:1 ration
Propeller shaft: 7/8"



Intro

This is just to share some interesting lessons learned that might apply to similar set ups or sister boats. For general instructions on how to do this please see.
http://www.pbase.com/mainecruising/stuffing_box

Disclosure: what follow is for information purpose only. What you do with your boat is your responsibility. Some have reported significant amount of water flowing in once the stuffing nut is removed so it is your responsibility to make the right decisions before attempting any project.

Tips and tricks

After picture (wet due to cleaning)
  • In my case the stuffing box body was tight enough around the shaft that the leak was minimal after I removed the packing nut.  So I did my job with the boat in the water. The water flow increased over several minutes but it was still well within what a bilge pump or manual pump can handle.
  • I used narrow pipe wrenches. In my case the two nuts measured 45mm and 50mm. Big, crude plumber wrenches might not work well. Look for something sturdy but narrow that can properly grab the nuts.. I used RIDGID E-110 Hex Wrench. Just FYI.
  • The packing material for my stuffing box was 1/4" Flex. 
  • The packing gland in my case is so close to the gearbox that you can barely unscrew the stuffing nut and move it away from the rest of the packing gland so you can work on it. Be prepared and check yours before you start
  • to remove the old packing, that is hard as a rock initially, I used a long wood screw. I carefully thread it into the stuffing for about 5 full rotations and then gently wiggled it back out. Do make sure to stay away from the shaft, you do not want to scratch it! Same for the stuffing nut albeit it is less critical. It worked like a charm and cut my time in half once I realized I could do that. I pulled the first of three stuffing sections using a picker and it took for ever since the only way to really get it out is to carefully find the splicing point and use that as leverage. Using the screw method above it is straightforward and considerably faster, just align the screw with the shaft so not to touch it and go.
  • Once I put it all back together with new packing, I hand tight it and left it soaking overnight. There were no leaks already. The next day I unscrewed it until I saw water dripping, then slowing tighten it until the leak stopped. Secured the counter nut, started the engine and tested that it drips every 30 sec or so. Ditto, done.

Monday, April 1, 2013

Porsche Boxster M96 engine: Intermediate Shaft Bearing replacement

In a nutsheel

  • 2003 Boxster, 2.7l M96 engine, stock
  • 91K miles
  • oil drip started a number of weeks prior to service
  • ~1sec rattling noise at start up started at about the same time as above and became more and more frequent up to occurring at every engine start
  • no other signs of problem
  • Not to give away the ending but this is a happy ending story
  • Not a DIY project for beginners, or even intermediate IMHO

Intro

There are a ton of blog posts about this, I am not going to replace them or repeat any of them. The purpose of this blog is to share some information I did not see anywhere else and to share some photos so you know what to expect. The best way for you to start is actually pelicanparts.com then come back here for some tips from a DIY who has done it...successfully.

A word of caution: I am sharing this information for your knowledge.  Quite frankly, I advice against doing this yourself since the risk of destroying the engine by accidentally skipping the timing chains is very much real.  As they say...

Do not try this at home. 

FYI: I rebuilt my first engine at 14, I can do most regular maintenance on my cars blindfolded. My dad has a mechanical engineering degree and though me a ton about cars before I could walk. I have two degrees in engineering and I have been working on engines for decades as DIY. Even at that I took a calculated risk and I quadruple checked the cam alignment to the level of paranoia since a mistake in this project is very, VERY expensive. Again, do not try this at home. 

Ok, I am done with the disclaimer.

Tip 1

If your engine is dripping slowly from the place where the transmission meet the engine and/or if you hear a gentle rattling sound at start up that lasts about a 1 second, you might have my very same condition and you should have your car serviced. In my case the bearing seal clearly gave up and the high temperature grease of the sealed unit was completely gone and replaced by engine oil. I am convinced that this bearing was on its way to self destruct, I caught it just at the beginning of the process. For the record, oil should not be present inside this bearing since when this happens, the oil is basically trapped inside the bearing and it will slowly collect debris and start wearing all moving parts. It is a slow process but it will eventually result in the bearing failure and, judging from the increase in frequency of the noise above mentioned, the degrade accelerates exponentially once it starts. I bet if I waited another few weeks, this would have sounded (and looked) much worse. This unit was starting to show signs of excessive play once I removed it but, again, I did catch it in time so I had no damage. As you can see from the photo, it clearly has oil in it (seal removed) so I was sitting on a time bomb. Lastly, the noise at start up is gone. I suspect it was coming from the balls skipping and sliding in the races until they caught up with the RPM of the engine.

Tip 2

Take your time if you DIY and put every nut/bolt back where it come from loosely as you remove a part. It might be time consuming but it makes reassembly a stress free ride. I used this tip for the big bolts connecting the transmission to the engine. Not only they ARE different from one another, at some point Porsche changed what bolt was used in what hole so your engine will likely be different than some of the blog posts out there. In my case it looked like one bolt was missing. In reality, my car was assembled in the factory with different bigger bolts but they also decided to use one less than the first generation engines. Do not panic, just mark them clockwise (that is how I did it) and just put them aside. I used the triple square on the bottom left as my n.1, then went clock wise and marked each hole and each bolt with a marker and then I moved to the transmission removal step (not covered here). Here are some shots of the work in progress. It also shows the IMS cover after the replacement with T-Curil and the new sealed bolts. That takes me to the next tip.

Tip 3

Do use new bolts on IMS cover, on the pressure plate and on the flywheel. I forgot to buy the latter and de facto I had to stall my project for a few days. Learn from my mistake! In general, make sure you order everything you need ahead of time. Do not short cut, follow the instructions from a proper service document and replace everything they say to replace. This is the mechanical systems that grabs the 225Hp from the engine and transfers it to the rear wheels. It is not the right place to be on the cheap IMHO.

 






 

 

 

 

 Tip 4

I have read that both Porsche and the Bentley service book say that after you torque the flywheel bolts, that each need to be turn an additional 90 or 120 degrees (Bentley say the latter). I used the fact that the bolts stars have 6 tips (see close up of the inside of the bolt) so I market the position of one tip WRT the flywheel after I torqued them, then marked two tips counter clock wise from it. Then I turned the bolts as close as having the two marks meet. I did not stress about doing exactly 120 degrees since I did the process by hand and I could tell when I was getting to a similar amount of effort required to rotate them. So effectively I stretched them at least 90 but not more than 120 degrees. Again, I have driven the car several hundred miles since, for what is worth. BTW Obviously you need to use a flywheel lock when doing this, look it up.


 Tip 5

Do buy a clutch alignment tool, it makes life incredibly easy during re-assembly and it is the cheaper tool you will need to buy for this project!
 

Tip 6 

Do replace the clutch while you are in there. Not only it is a smart thing to do, it will also give you a brand new car: my original clutch was considerably harder and more difficult to manage than the new one. In the nearly ten year since the car was built they redesigned the pressure plate (despite looking identical to the old one) and it works incredibly better! It is like driving a new car.


Tip 7

Manual transmission cables do pop from their ball pins. Just be gentle and apply even amount of force on both sides of the connector and they will pop. Disconnecting and reconnecting these cables is incredibly easy. DO make sure you memorize which cable goes where. They have different length so it is straightforward but do pay attention so you do not panic during re-assembly.

Tip 8

Last but not least, I took a simple approach during disassemble: keep all the parts that came from the left side on the left side of the "pile", conversely for the right side. This way I ended up with parts lined up next to the car on either side and it was a breeze to put them back. Things like the transmission mounts (which BTW double as engine mounts so DO support the engine with floor jacks) are symmetrical. Albeit they are clearly labeled with instruction as to which side they go, I still enjoyed the approach and made the process safe and effective. Not to mention that keeping things organized methodically will let you sleep better at night and it will lower your hearth rate when you finish the job and drive the car for the first time ;-)





Tools I used (it might help you create your project list)

  • full set of Torx
  • full set of metric sockets
  • full set of metric hex
  • M10 triple square, if you do not know what it is, look it up, it is educational
  • clutch alignment tool
  • a 32mm socket to remove/loosen the chain tensioners
  • a filter cover removal tool, hands or one-size-fits-all will not work!
  • lots of WD40 to clean and lubricate all the bolts/nuts prior to loosening them. Remember you are working on parts that have been untouched for years, be gentle and let the loosening agent do its thing
  • a breaker bar socket wrench
  • a couple of torque wrenches of different size




Saturday, December 8, 2012

2003 Porsche Boxster alternator replacement

Problem: Voltage drop when engine running. Normally the alternator should feed 13 - 14.7 Volts to the battery. Mine was at 13V when I first diagnosed the problem and then went to 12.3V (basically nothing atop the battery itself). In my case I also experienced one short light of the battery light on the dashboard. Most likely this is when the voltage regulator died.

Solution: the voltage regulator is likely the culprit. You can read a lot more here http://www.pelicanparts.com/techarticles/Boxster_Tech/82-ELEC-Alternator/82-ELEC-Alternator.htm
I ended up replacing the whole alternator with a rebuild one but if time is not of the essence you can order the voltage regulator from Pelican Parts and save about $100 (a re-manufactured alternator should run you about $170, if you are paying more you are probably being ripped off since the VR costs about $36 retail). From what I have read it is a good idea to just put a fresh rebuild alternator instead of changing only the VR but I will leave to your taste.




Tips and trick not available elsewhere:
- in a 2003 and likely older model Boxster/Cayman there is no point in disconnecting the engine lead cable in the engine bay as described in most how-to blogs (i.e. the link above). The wire has been modified into a Y-split and the third leg of the Y is still connected after you disconnect from the engine bay so you still have no gained any more mobility when working on the alternator connections. Just be careful when you do remove it and install it and leave this lead alone.
- it is a real pain to re-align the new alternator bolts, I used a strap to lift some of the weight of the alternator from the top so that it would move and rotate in place more easily.
- you will likely have all kind of problems getting the right hand side bolt to thread. In my case the alignment was a left to right issue more than a vertical matter (it will make sense once you do it, just check for it when it is time) and I had to push it towards the center of the car to make the holes to align.
- The right hand side bolt actually double as a pivot point for the alternator (sort of) and I tried install it with the left bolt in place and just "hook it" from the top into the grove built in on the engine blick but you basically have no visual to align it so it is a one in a million shot (look at said groove after you remove the old one, you will know what I mean). I used the technique above instead.