Notes on PHP: Restart apache won’t reset php session

 

To be honest, it is a little odd that PHP session won’t be destroyed after Apache server got restarted. In order to truly kill the PHP session, especially during development, I created a piece of following code, and ran it everything I wanted to have a clean start:


<?php

session_start();
unset($_SESSION['session_name']);
session_destroy();

?>

 

Drive computer vision camera (Point Grey) on single-board computer (Banana Pi)

Computer vision cameras come with extremely small size without too much compromise on image quality. They fill in the holes of a wide range of applications that conventional photography cameras are not capable of.

One drawback, however, is the fact that they don’t have large on-board storage. That is to say, the data must be streamed out to some external storage. A dumb computer could be a good company for the computer vision camera, but this combination will cost the computer vision camera its advantage of size. Image that if you want to build a computer vision camera rig, then a large of computers will be required, which is very likely to make the maintenance work become nightmare.

Given the fact that those dumb computers are only there to receive and store the data, with no need to all the advanced stuff such as CPU computing power or graphics performance. In this case, is it possible for those super cheap single-board computers (embedded system) to take over the job? The good news is, YES!

According to Point Grey’s website, they’ve already tested their cameras with single-board computers such as Jetson TK1 from Nvidia and ODROID-XU. How about others, the popular Raspberry Pi or Banana Pi? Especially the latter one because it comes with a SATA port, perfect for a SSD storage.

P1040148_1920
A stereo set of Point Grey Flea3 FL3-GE-50S5C connecting to Banana Pi BPi M1 + SSD storage

After downloading the ARM SDK and the sample codes into the Banana Pi, the first tryout gave me the following error:


There is an image consistency issue with this image

What does it mean? It means your data receiving part (which is the Banana Pi) can’t catch up the speed with the camera. So the image you received is likely corrupted.

How to solve it? Fortunately, you only need to tweak the parameters on  the camera as well as the OS (e.g. Ubuntu) on the embedded system:

  • Packet Size and Delay on the camera
  • Receive Buffers on your OS

I will take a little bit more in my next posts regarding tweaking of those parameters. Once I got everything work, I was able to achieve 4fps of the RAW data from its 5.0 MP sensor, that is roughly 80MB/s. When I tried to increase to 5fps, I got the “image consistency issue” back from time to time. I believe there still should be a little more juice to squeeze out of the Banana Pi by tweaking the above parameters.

 

How to rework small surface mount LED

I talked about soldering small surface mount LED in my previous posts by using DIY reflow oven. Today I would like to show you how to rework similar LED, which is, to desolder this LED off the PCB and solder a new one on it.

It is quite different from populating a bare circuit board because the board comes with all types of other components. Rework process is more to fix a problem than to create new damage, so I will need to focus on the target LED only, not to affect other ICs. The LED is from Philips Luxeon Rebel series, about 3mm x 5mm in size. The pads for soldering are on the bottom of the component, making it impossible to solder with the traditional soldering iron

Heat gun is a great tool for this purpose as it is good at spot heating. With proper procedure and handling, the removed LED might still be reusable.

Stencil, unfortunately, couldn’t be used in this situation to assist the solder paste applying process. However, thanks to the surface tension, manually applying the paste onto the solder pads still work for this job. Don’t worry if they look messy at the beginning.

Check out my video for more details!

LED_Rework_1
The one with yellow bulb was just reworked.

Teardown of Ricoh Theta 360 Degree Spherical Panorama Camera

The first impression of the Ricoh Theta 360 Degree Spherical Panorama Camera is its odd appearance — to me it feels like a bar of chocolate wafer. The dual lens reminds me of the bubble eye goldfish. For some reason I was given this 1st generation Ricoh Theta camera for free, but broken. So why not taking a peak at its inside?

The camera was wrapped with aluminum straps by double-sided tapes to cover the screws. Removing the straps would expose the screws. And that would be the starting point for the teardown.

Siding removed.
Siding removed.

There were quite a few screws on the sides. Once they were all gone, the cover popped up easily. Now you can see what’s enclosed: battery; circuitry and optical module. Looks like each section takes equal amount of space inside the camera body.

P1030133
Open up the body

The Li-ion battery (model: DB-100) is quite beefy, to be honest. It is actually a Ricoh’s standard rechargeable battery product, which is also being used on CX5, CX4 and CX2 cameras. No wonder it looks a little over-sized for the slim panorama camera. I guess Ricoh could cut down the cost by doing so.

A big battery.
A big battery.

Panorama camera is equipped with a RS-WC-201 wireless module from Redpine Signals. This module supports 802.11b/g and single stream 802.11n, up to 65Mb/s. Retail priced at about $65.00USD from Mouser. Same feeling for the battery that it is also quite big….but off-the-shelf means lower cost, why not?

Wireless module RS-WC-201
Wireless module RS-WC-201

Unplugging the wireless module will expose the mother board and the optical assembly. The optical assembly, featuring two big fish-eye like lens in a back-to-back configuration, is well sealed and weighs a lot. A metal strap was wrapping around the lens, and was soldered on to the mother board through black jump wires. I guess that was some sort of anti-static protection since the camera design made it very likely for a user to touch the lens. Although the lens is a passive component, prone to electrical discharge, the enclosed image sensor (I will show you later) may get affected if the lens takes the charge.

Optical module.
Optical module.

The mother board is actually bigger than my first glance. It goes under the battery, covering the whole body except for the lens area.

Battery contacts on the mother board. The battery is actually riding on top of the mother board.
Battery contacts on the mother board. The battery is actually riding on top of the mother board.

Another interesting discovery from the back of the mother board is that the Theta camera is utilizing a 4G micro SD card as extra storage.

FPGA and 4G micro SD card on the back of mother board.
Spartan-6 FPGA and 4G micro SD card on the back of mother board.

A piece of metal shield covers the ARM processor and the memory chip. The ARM processor is Fujitsu Milbeaut Image Processor MB91696AM, equipped with a dual-ARM core and built-in H.264 codec that supports Full HD video. This processor seems to be 4~5 years old already, its maximum of 5.5fps at 20MP doesn’t look too fancy on today’s market. That’s probably part of the reasons why Ricoh has released a new generation: Ricoh Theta S. The memory chip from CHIPSIP model CT49248DD486C1 is NAND(1Gb)+DDR3(2Gb). So my question is, if the storage size could be easily increased by using a bigger NAND chip, what is the necessity for an add-on micro SD card? Maybe it is easy to make models for different memory size?

Metal shield covering the ARM processor and memory chip.
Metal shield covering the ARM processor and memory chip.

The Xilinx Spartan-6 FPGA, the dual-core ARM processor and the memory chipset make the image processing engine for the Ricoh Theta camera. What makes it different from all other cameras is the unique optical/image sensor assembly that is capable of capturing 360° panorama photo.

Side view of the optical / image sensor module in a compact package.
Side view of the optical / image sensor assembly in a compact package.
Top view of optical / image sensor module in a compact package.
Top view of optical / image sensor assembly in a compact package.

I took the photo below as I though this would be the end of my teardown work of the Ricoh panorama camera. But I was wrong! Please read on as more interesting discoveries are ahead about the well engineered optical / image sensor assembly.

Disassembled Ricoh Theta Panorama Camera.
Disassembled Ricoh Theta Panorama Camera.
Disassembled Ricoh Theta Panorama Camera.
Disassembled Ricoh Theta Panorama Camera.

The two circuit boards on the top and bottom of the optical assembly are actually the image sensor boards. I didn’t realize this until I further tear down this assembly. It was hard to image how a sensor is not directly behind a lens, but on the side looking through a diagonal mirror. What a smart design! Since the image sensor is no long taking up the space behind the lens, the back-to-back dual fish eye lenses could get as close to each other as possible. This, presumably, will leave a smallest as possible seam between the two 180° panorama photos. I guess this would make software engineer a much easier job to stitch the photos.

The optical / image sensor module was so well packed that it took me and my colleague some serious efforts to open it up. I noticed that some glue was used for the packaging, so the teardown of this assembly is an irreversible process. It was causing permanent damage to the assembly. So think twice before you try this.

The image sensor got knocked off first. I wasn’t able to tell its maker or the model number. Given the limited number of pins on the connector, I guess it is a rolling shutter sensor.

Top and bottom view of the image sensor.
Top and bottom view of the image sensor.

Once the sensor was removed, I was able to prove my assumption of its right angle optical path. As you can see from the photo below, I shined some yellow light on the right side, and the color showed up on the top. Same thing happened on the left side where the image was reflected down. There must be some sort of double-sided mirror placed in diagonal direction.

Image on the right gets reflected up, the left down.
Images from sides of the Theta panorama camera lens are reflected up and down to respective image sensor.

After the out-most convex lens was gone, we were able to take a further step into the heart of the optical module. But we were stopped by another piece of lens.

A second lens along the optical path
A second lens along the optical path

After another desperate digging, knocking and poking, the 2nd lens was finally gone. And the core of the optical module was just a friction of an inch away.

Lens module stripped to the core.
Lens module stripped to the core.

Finally we were able to grab the core: a beam splitter like cube that is made of two prisms glued together, forming a double-sided mirror on its interfacing surface (45°).

Theta Panorama Camera mirror cube.
Theta Panorama Camera mirror cube.
Theta Panorama Camera mirror cube.
Theta Panorama Camera mirror cube.
Theta Panorama Camera mirror cube.
Theta Panorama Camera mirror cube.
141028theta02
Lens design diagram of Theta camera

Here is the photo of all the parts that were ripped off from the optical / image sensor assembly.

Ricoh Theta Panorama Camera optical / image sensor disassembled parts。
Ricoh Theta Panorama Camera optical / image sensor disassembled parts。
Ricoh Theta Panorama Camera optical / image sensor disassembled parts。
Ricoh Theta Panorama Camera optical / image sensor disassembled parts。

DIY, how to build your own cantilever sliding gate (8) – Mount the fencing board!

I’ve decided to decorate the sliding gate with fencing board from the very beginning. Now the posts were set, the gate was assembled, and the gate opener was installed and powered. Finally, it’s time to start mounting the fencing boards to finish this project!

There are many different ways to mount fencing boards on round steel pipes. The two most common ways shown in the photo below, however, wouldn’t work for me. I couldn’t mount the boards flush against the frame pipes because the cantilever roller will need to roll on the horizontal pipes. Nor would I cut the boards shorter to avoid protruding the top & bottom frames because I wanted to use full 6 ft length of those boards. This way, I will be able to keep the sliding gate same height as the neighboring fence.

Two fencing board mounting methods that won't work me: (Left) boards cut short and cantilever rollers exposed; (right) board mounted flush against the pipe frames.
Two fencing board mounting methods that won’t work me: (Left) boards cut short and cantilever rollers exposed; (right) boards mounted flush against the pipe frames.

My idea solution would be mounting the boards a few inches away from the gate frame to allow free rotation for the U-groove rollers. The fencing boards, or the top/bottom rails still attach to the frame, but not flush against the it. This will keep the top and bottom pipe clear of any obstacles for rollers. The photo below show how I spaced a few inches between the gate frame and the fencing boards.

Top and bottom fence rails are attached about 1 inch away from the gate frame.
Top and bottom fence rails are attached about 1 inch away from the gate frame.

The key elements here are some home-brew brackets that were welded on the gate frame, but not touching any area of the very top or very bottom of the gate frame.

The 2 by 4 fencing rail will sit against the L shape bracket.
The 2 by 4 fencing rail will sit against the L shape bracket, leaving enough space for the U-groove roller.
Another type of rail supporter.
Another type of rail supporter.

Finally, it’s time so say good bye to the old gate!

Remove the old gate and attach the fencing board. Check out the time-lapse!
Remove the old gate and attach the fencing board to the new gate frame. Check out the time-lapse!

DIY, how to build your own cantilever sliding gate (7) – Install the gate opener

There is a wide selection of gate opener products available online or at local shop, The price would range from several hundred dollars to more than a grand. It is really hard to tell the difference by the appearance. After intensive research on reviews, I decided to purchase the ALEKO AR1450 sliding gate opener with gear rack.

AR1450, courtesy of ALEKO product.
AR1450, courtesy of ALEKO product.

It comes with the kits that meet all my basic needs in my plan:

  • Gate opener.
  • Two (2) remotes.
  • Mounting bracket.
  • Anchor bolts.
  • Screws and nuts.
  • Gear lock/unlock key.
  • 20 ft (3.3 ft x 5 pcs) linear gear rack.

Other specs all look fine to me:

  • Opens gates weighing up to 1600 lbs. — Mine won’t be more than 300 lbs.
  • Opens gates up to 55 ft. in length. — Mine is about 12 ft in length.
  • Soft starting / stopping
Gear-driven vs chain-driven

Chain-driven is the most common way to drive a sliding gate, it’s relatively cheaper and easier to install. However, gear-driven mechanism produces quieter and smoother transition. Plus, the linear gear rack looks more attractive than the sagging chain.

Chain-driven vs. gear-driven.
Chain-driven vs. gear-driven.
Receiving the packages

The first impression upon receiving the packages were heavy, both for the AR1450 opener and the nylon gear racks!

Two boxes: one for the opener; another for the gear racks
Two boxes: one for the opener; another for the gear racks

Don’t worry if you couldn’t find the remotes, they were actually hiding inside the opener’s plastic cover. Removing the plastic cover will expose the key components: the giant motor taking most of the space, the circuit board leaning against the motor, magnetic sensor and capacitor. It is not necessary to understand what they are. All you need to do is to wire your power cord to the connector shown in the photo below.

Wire your power cord to the connect in circle. All the rest of the system is pre-wired out of package.
Wire your power cord to the connector in circle. The rest of the system is pre-configured by manufacturer.

As soon as you get power cords connected correctly, the indicator on the circuit board will light up, and you can immediately control your opener with the provided remote! For tweaks like changing open/close direction, increasing/decreasing force or enabling pedestrian mode, you will need to dig a little deeper into the manual. Other than those, the gate opener almost requires zero effort on the electrical setup. Most of my work, however, was spent on the masonry work — taking measures, assembling mold and pouring concrete for the opener’s base.

Assemble the mounting base and concrete mold

It took me quite sometime to figure out how to assemble the metal mounting base for the gate opener as the manual didn’t seem to be very helpful on this topic. The assembled mounting base looks like a mini oil rig: four anchors shown as below were to be buried in the concrete pouring to produce strong clamping force. Another set of bolts that go straight up are for the gate opener.

Mounting base assembly with anchor bolts
Mounting bracket assembly with anchor bolts

If you recall my last post about trenching, you’d probably have noticed that I dug a pretty big hole where the PVC pipe terminated. That hole was actually prepared for the gate opener. A rock solid base made by concrete is very important for the gate opener to provide enough force to move the gate. The hole was about 2 ft wide by 2 ft long, 1.5 ft deep. Since the gate opener was measured to be installed at 8″ above the ground, I made a mold of the same height with width / length at about 1′ / 1’4″. Mold was then installed on the site with proper bracing and supporting to receive concrete.

1. A mold to lift the gate opener 8
1. A mold to lift the gate opener 8″ above the ground; 2. The mounting base will be installed on top of the concrete; 3: Mold was setup on site; 4. Conduit was extended above the mold.

After I acquired a cement mixer (shown below), my concrete pouring work became so much fun! Before that, I was basically mixing it with shovels….worked fine but not easy. I depleted fours bags of 60 lbs concrete mix to fill up the mold for the gate opener base pad. So total 240 lbs, Heavy!!! Considering the force the motor is going to push on the gate, the heavier base really pays off.

Cement mixer I purchased from craiglist.
Cement mixer I purchased on craigslist.
Concrete mix is still wet. Note the mounting bracket is placed on top of the mix with the four anchor bolts buried inside.
Concrete mix is still wet. Note the mounting base is placed on top of the mix with its four anchor bolts being buried inside the mix.
Concrete mix started curling in the following hours. Wait at least one day before removing the molds.
Concrete mix started curling in the following hours. Wait at least 24 hours before removing the molds.

After I removed the mold, I painted the concrete base with wall sealer. Totally unnecessary, but I just happen to have it around. So why not?

Paint wall sealer onto the curled concrete base.
Paint wall sealer onto the curled concrete pad.

Now the concrete pad is ready to receive the gate opener. Make sure the opener is not too far nor too close to the gate frame. Measure the distance by roughly placing a nylon gear rack on the gate. When you are happy with the position, lock the opener with nuts provided. Make sure the opener is tightly secured on the mounting base.

Install the gate opener and adjust the position.
Install the gate opener and adjust the position.
Mounting the gear racks

If my gate were composed of square metal tubes, it would be fairly easy to mount the gear racks — just to place the racks flush against the frame and use self-tapping metal screws to fasten them. However, circular pipes like mine doesn’t provide any flat surface to be flush against. I would have to “create” some.

Looking back into the gate opener kits, I noticed one type of parts that I never realized what to do with before. The small metal bracket shown in the photo below is actually a piece of perfect gadget to “create” such flat surface for the purpose of mounting the gear racks on round pipes.

Bracket for mounting gear rack on round pipes.
Bracket for mounting gear rack on round pipes.

In order to “create” such flat surface, I would need to weld this bracket on to the pipe. Since I welded the whole gate frame together, this small task wound’t be a challenge for me any more.

Use a piece of scrap wood/metal as alignment.
Use a piece of scrap wood/metal as alignment.
Welding a
Welding a “L” shape bracket on to round pipe to create flat surface for the purpose of mounting gear rack.

I still don’t know if I am making correct use of those brackets, but they do look perfect for this purpose. The bracket has a open slot in the middle, so I could easily adjust the height of the gear rack. Here is the final assembly of the gear racks on those brackets, and I connected four racks together to make a 12-foot long continuous gear rack.

Long continuous gear rack made by four pieces connected together.
Long continuous gear rack made by four pieces that are connected together.
Magnetic Limit

This ALEKO AR1450 gate opener relies on magnetic limit to control the stop of the gate. Basically the magnetic limit is mounted on the gear rack, when the sensor inside the opener senses the passing magnet, it will trigger the stop operation of the motor. Two sets of magnet / brackets are provided in the kits: a taller one for gate open limit; a shorter one for close limit.

Magnet is approaching, the gate is about to stop.
Magnet limit is approaching, the gate is about to stop.

Note that the gate won’t stop immediately when it sense the magnet, the control circuit inside the opener will ramp down the rotation of the motor. When choosing the location for the magnet limits, make sure leave some buffering distance before the gate completely stops. This is very good design of the gate opener to have the ramp up / ramp down mechanism. Without it, the abrupt start or stop will result in tremendous momentum on the gate frame, gate opener and posts, just like the gate is actually crashing on the gate opener every time it starts for stops moving. Frequent crashes day after day like this will eventually break the gate and the opener.

[Edited on Mar 28th, 2016]

In case you would like to know more details about wiring the AR1450 mother board, please refer to the following image that came with the product.

Detail wiring diagram of AR1450 gate opener mother board.
Detail wiring diagram of AR1450 gate opener mother board.

DIY, how to build your own cantilever sliding gate (6) – Run the power cord through underground conduit

Gate frame is up, now it’s time to do the electrical work. First of all, I needed to have power on the site! After searching around the house, I decided to run the power cord from my garage. I already noticed that my garage is on a 25 Amp breaker in my plan. 25 AMP should allow enough juice to flow through for the gate opener.

  1. Drill a hole through the wall and run the cord to the outside.

    Care must be taken on the location where to extend the power cord. It’s better to start from the main power cord directly from the breaker panel. DO NOT extend the power cord from a light fixture or an outlet. I used 12-3 building wire for my total extension distance of about 40 feet. Smaller gauge (thicker copper) might be necessary if the distance is longer.

  2. Install a pull box on the outside wall.

    Pull box mounted on external wall
    Pull box mounted on external wall
    Drill a hole through the wall so that the power cord could go outside. Hang a pull box on the wall and now you can terminate the power cord inside it. Just like the name, a pull box is where you can “string” and “pull” the wire that will need to go somewhere, or in my case, across the yard. There are various options for a pull box shown as the photo below. I chose a relatively big one because I needed to install an outlet in it. I used a GFCI outlet because the outdoor environment is prone to get wet and cause electrical shock. And plus, I could use the “TEST/RESET” button as a switch to turn on / cut off the power for the gate opener without affecting the rest of the garage. This idea turned out to be very useful, especially during the installation process.

    Left: pull box for cords only. Middle: my pull box with a built-in GFCI outlet. Right: GFCI outlet.
    Left: pull box for cords only. Middle: my pull box with a built-in GFCI outlet. Right: GFCI outlet.
  3. Dig a trench for the conduit across the yard and lay the PVC pipes.

    According to the local code, I needed to bury the conduits 12 inches deep if I use PVC pipe. It took me some serious efforts to dig the trench, especially when the dirt is dry and hard. I highly recommend dampening the soil first before putting your shovel on it.

    Trench starts right below the pull box.
    Trench starts right below the pull box.

    Dig across the yard. Should have done it straight....
    Dig across the yard. Should have done it straight….

    Ending of the trench is the place for the gate opener.
    Ending of the trench is the place for the gate opener.
    Worrying that I don’t have the tool to string the cord through a long pipe, I was struggling between stringing-wire-before-laying-pipe and after-laying-pipe. However, stringing the wire in advance didn’t turn out to be an efficient way as the PVC glue and dirt together were just enough to make everything in a mass. Miraculously, I though of my drain cleaner snake and it ended up to be a great tool for this job!

    String the wire through the conduit by using a drain cleaner snake.
    String the wire through the conduit by using a drain cleaner snake.

    PVC pipe runs down from the pull box and across the yard.
    PVC pipe runs down from the pull box and across the yard.

    PVC pipe terminate at where the gate opener will be installed.
    PVC pipe terminates at where the gate opener will be installed.
  4. Cover with trench and seal the conduit for next step

    Now it's ready for the gate opener.
    Now it’s ready for the gate opener.