I was experimenting with the FTS3/FTS4 feature of SQlite in a WinRT app. The default tokenizer ‘simple’ wont tokenize special character like $, @, etc. The solution is to use ‘unicode61’ tokenizer. Unfortunately the SQLite installer for WinRT8.1 comes without unicode61 tokenizer. I searched a lot to get a SQlite WinRT build that supports unicode61 but I was not lucky enough to get one, so I decided to build one myself.
Tim Heuer have a great post explaining about creating a build of SQLite for WinRT, I went through that and acquired all the tools to build, including the SQLite source code. I did exactly the same way Tim explained in the video, finally I got my build. But again it has the same issue, not supporting unicode61 tokenizer. I tried several builds and all these time I build with DSQLITE_ENABLE_FTS4_UNICODE61=1 and other flags I mentioned below.
After several attempt with so many permutations and combinations, I got it working. Tim’s video is a very good reference for building SQLite for WinRT. But if you want unicode61 support then follow the below steps, it’s same as Tim’s explained with some exclusion.
- mkdir c:\sqlite
- cd sqlite
- fossil clone http://www.sqlite.org/cgi/src sqlite3.fossil
- fossil open sqlite3.fossil
fossil checkout winrt,never issue this command, it will never include unicode61
- Added this step to enable unicode61 tokenizer. Append the below config to Makefile.msc, you can see some config already existing append the below config to it.
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_FTS4=1
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_FTS3_PARENTHESIS=1
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_FTS4_UNICODE61=1
- Compile the code by issuing nmake -f Makefile.msc sqlite3.dll FOR_WINRT=1
I could build X86 and X64 using VS2012 command prompt for X86 and X64. But when I tried to compile for ARM I was getting some errors, I was fortunate enough to find a solution in StackOverflow. Followed that solution and I got the SQLite builds for X86, X64 and ARM.
I don’t want to spend time in creating a vsix package and install it in my machine, instead I took the backup of SQLite for WinRT version 3.8.5, in my machine the installed path is C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1\ExtensionSDKs\SQLite.WinRT81. Then went into each folder and replaced the lib and sqlite dll with the respective builds I created.
Leave your comments if you have any questions.
In this post I will explain how to access Raspberry pi via Internet. I am trying out a home automation system using Pi and I wanted to access a node.js service running in my Raspberry pi. Also I may wanted to SSH to the pi to restart or configure it while I am away from home.
Configuring the Router
In my home Raspberry Pi is connected to a Netgear R6300 router. The router is then connected to a DSL modem. In these kind of setup we might be dealing with four different IP’s
External IP assigned to you by your ISP.
IP Address of the modem
IP Address of the Router assigned by the modem
IP Address of the Raspberry Pi assigned by Router.
Credentials to login to the Modem configuration.
Credentials to login to the router configuration.
External IP: you can get your external ip by visiting whatismyip.com
IP Address of the Modem and Router: As I am using Netgear modem, I login into Netgear genie app. And from the Internet section I could see the IP Address assigned to my router as shown below.
As you could see the IP address assigned to my router is 192.168.1.2. Also you can see the Gateway IP address 192.168.1.1, that IP will be the IP address of your modem.
IP address of the Raspberry pi: SSH to Raspberry PI and issue ‘ifconfig’ command and you can see some details and check wlan0 as shown below. Line in bold shows the ip address of the Pi.
wlan0 Link encap:Ethernet HWaddr 04:a1:51:6a:fb:8d
inet addr:10.0.0.10 Bcast:10.0.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:5543 errors:0 dropped:11 overruns:0 frame:0
TX packets:1799 errors:0 dropped:0 overruns:0 carrier:0
RX bytes:1200798 (1.1 MiB) TX bytes:192891 (188.3 KiB)
In my scenario I assigned a static IP to this Pi, other wise router’s DHCP server will assign ip and might change from time to time. So most router have configuration, to set static IP to the devices and will never change. At my house most of the devices like TV, Tabs and Raspberry PIs have static IP’s and the guest devices uses DHCP assigned IP’s.
Let’s configure SSH to the Pi from internet.
Router Port Forwarding
Excerpt from Genie help
Port forwarding is designed for FTP, Web server, or other server-based services. Once port forwarding is set up, requests from the Internet are forwarded to the proper server.
In the Genie app you can find Port forwarding in Advanced setup->Port forwarding/Port triggering, you might be able to find some thing similar in other modem’s configuration.
I clicked ‘Add Custom Service’ button and it will show the below screen to setup Port forwarding configuration. Here I am configuring SSH.
Here 22 is the port where SSH server in my PI is listening. Internal IP address is the IP address of the Raspberry Pi. Click apply and the changes will get saved.
We setup the port forwarding in the router. We need to do the similar configuration in Modem.
Modem Port Forwarding
Enter the IP address of the modem in the Chrome/IE, enter the user name and password if prompted.
Note: My DSL modem is pretty old one and may not be match with the interface of your modem configuration screen.
The port forwarding configuration in my Modem is located at Advanced Setup/NAT/Virtual servers. See the configuration below.
Here I setup the external port number as well as internal port number. You can have different external port number if you want, say for e.g. external port number 8090 can be mapped to internal port number 22. The server IP address should be the IP address of the router.
Check whether the port is opened by going to yougetsignal.com, if the port is still closed then you might need to do Port triggering in Modem as shown below.
We successfully configured SSH to Raspberry Pi from internet, you can check using a machine connected to a different network and connect to Pi using any SSH client like Putty. While connecting the IP address should be the external IP address and the port should be the one configured in Modem, here it’s 22.
The above approach will work, in case you want to open any port, I have a node.js service listening to 8090 in the same Raspberry pi. I did the above approach to access it via internet.
Leave your comments if you like this post or in case of any questions.
In my last post you can see the Tracker in action. This post I will explain the code running in Raspberry pi that controls the Tracker. I use Wiring Pi to control the GPIO instead of the default RPI.GPIO. The intention of using Wiring pi is because Software PWM is easy to implement. Any way after the first run of the tracker I realized that my tracker is slow moving one and no need to control the speed, so I haven’t used Software PWM here.
Installing Wiring Pi for python
Command prompt type the below commands
sudo apt-get install python-dev python-pip
sudo pip install wiringpi2
Let’s check whether wiringPi installed correctly
if it returns a value then wiring Pi installed successfully.
Pi Tracker php code running in Raspberry pi
import wiringpi2 as io from time import sleep class Motor: def __init__(self, gpio_a, gpio_b): self.Gpio_a=gpio_a self.Gpio_b=gpio_b self.activeGpio=gpio_a def setup(self): io.wiringPiSetupGpio() io.pinMode(self.Gpio_a,1) io.pinMode(self.Gpio_b,1) def forward(self): self.stop() self.activeGpio=self.Gpio_a def reverse(self): self.stop() self.activeGpio=self.Gpio_b def acclerate(self,speed): io.digitalWrite(self.activeGpio,1)
#speed param is not used here. def stop(self): io.digitalWrite(self.Gpio_a,0) io.digitalWrite(self.Gpio_b,0)
from Motor import Motor class Engine: motor_a=Motor(17,27) motor_b=Motor(23,24) def __init__(self): Engine.motor_a.setup() Engine.motor_b.setup() def steer(self, command): direction,speed=command.split(",") if(direction=="CLOSE"): self.stop() elif (direction=="U"): self.forward() elif (direction=="L"): self.left() elif(direction=="R"): self.right() else: self.reverse() def forward(self): Engine.motor_a.forward() Engine.motor_b.forward() self.acclerate() def reverse(self): Engine.motor_a.reverse() Engine.motor_b.reverse() self.acclerate() def right(self): Engine.motor_b.reverse() Engine.motor_a.forward() self.acclerate() def left(self): Engine.motor_a.reverse() Engine.motor_b.forward() self.acclerate() def acclerate(self): Engine.motor_a.acclerate(10) Engine.motor_b.acclerate(10) def stop(self): Engine.motor_a.stop() Engine.motor_b.stop() print "engine stopped"
import socket from Engine import Engine TCP_IP = '10.0.0.10' TCP_PORT =5005 BUFFER_SIZE = 100 engine= Engine() engine.stop() s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) s.bind((TCP_IP, TCP_PORT)) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.listen(1) conn, addr = s.accept() print 'Connection address:', addr while True: try: data = conn.recv(BUFFER_SIZE) print "received data: ",data engine.steer(data) if not data: engine.stop() conn,addr=s.accept() except KeyboardInterrupt: conn.close() engine.stop() print "connection closing" except Exception as err: conn.close() s.listen(1) conn,addr=s.accept() #s.listen(1) print "error occured" pass conn.close()
How it works
Motor.py class represent a motor in the Tracker. It accepts two parameters and it should be a valid GPIO pin to which the motor is connected. For e.g Motor_a is connected to GPIO 17 and 27. If we give write 1 to 17 and 0 to 27 then Motor_a will run forward, write 1 to 27 and 0 to 17 Motor_a run reverse.
Pi Tracker uses two motors to drive, Engine.py controls these two motors. As you can see in the code Engine.py creates two Motor instance. It also has functions to steer the tracker in different directions.
trackerRemoteListener.py is the socket program that listens to the command from external device to control the tracker. To control this tracker I used an Android tab that sends the command to this listener.
Hope the code is self explanatory, if not post your questions in the comment section.
A new feature added to the tracker after the last post is the video streaming to the controlling device. In the modified tracker a USB camera is attached to the front of the tracker and connected to the Raspberry Pi. The RaspPi host a mjpg streamer and the video can be streamed to any device connected to the same network, including the Android device that controls the tracker. This helps my son to sit anywhere in the house and control the tracker.
Stay tuned for the next post with source code and more…
Edit: A new post added explaining the Source code running in Raspberry pi
I was always fascinated about software and hardware interaction. But with my limited knowledge in electronics, I kept the hardware part aside and was working only in software. After having some hands on experience with my first Raspberry Pi, I decided to build a toy for my son. I purchased my second pi and some other components and this is what I built. Yes it looks ugly but worth playing with it :).
Last couple of days I was refreshing my basic electronic skills and virtually designing the software and hardware for the device. You can find so many similar RaspPi based toys and I am adding one more to it.
Yesterday evening I got the last piece of the puzzle, the rechargeable battery. After that I spent the next 5 hrs to code the application running in the vehicle and the Remote control app for my Android tab, remote control app is based on the Acclerometer of the device. To control the toy I decided to use WiFi and use my Android tab as a steering wheel. I will go more details into the software part in a different post.
Obstacle detection and avoidance system
Video feed to the remote control device
Rest of the post will go through the components used in the tracker and how to acquire it. If you are in Bangalore then you can get all these items from OM Electronics in SP road or you can buy online. I bought it from OM Electronics.
Powder coated Metal chasis for robots. Easy to mount the motors on place by using normal motor mount nut. It can either be used in skid steel configuration (4 motors) or differential configuration (2 rear wheels + 1 front castor wheel). The body contains perforated holes for easy mounting of various size circuit boards and other mechanical components.
Length : 190mm
Width : 105mm
Height : 40mm
High quality Plastic Track Belt and Ribbit
|L293D Motor Driver controller
H Bridge to control the motors individually
male to male jumber wires – 10 or more pcs
male to female jumber wires – 10 or more pcs
female to female jumber wires – 10 or more pcs
|12V Lithium-Ion Rechargeable Battery
12v rechargable battery + charger
Next part I will go through the software part of the system. Stay tuned.
This post explains how different devices at my home connected via Wi-Fi and provide an easy way of streaming media contents. In this setup I created the playlists in one location (NAS) and all other devices can consume it.
Home network Topology
All my devices are connected to Netgear’s gigabit router. Earlier I had a 10/100 Netgear router and I replaced it with 10/100/1000 router. If you are planning for a streaming network at home its worth investing in a very good gigabit router.
Network Attached Storage (NAS)
The integral component of my streaming network is the 4TB WD My Cloud. It host twonky DLNA server and iTunes server, any DLNA complaint devices can connect to it and stream audio or video. Some devices at my home is not DLNA complaint, like docking station and Home theatre. That’s where Raspberry PI will be helpful.
I knew about Raspberry Pi since it launched but never used it until recently. I decided to use Raspberry Pi to make my non DLNA devices to play media from my NAS. There are so many tutorials available in the internet to setup a Raspberry Pi, using noobs installer and using Raspbian image, I use Raspbian image to setup.
Next is setting up my Pi to play media from a DLNA server, Stephen Phillips has a very good post explaining how to do it. Follow the steps and you will have a device that can connect to any non DLNA device to play media from a server. I then connect the Pi’s audio out to my Home theatre and could play audio from the NAS. Without raspberry pi I have to switch on my TV when ever I want to play audio, with this setup my TV can be switched off when I am listening to music, also it saves energy.
I can use my Android Tab as a remote to paly media using BubbleUPnP (paid and free) or from my Lumia 920 using AV Remote (paid and trial available) or a free app called myMediaHub. You can use any similar apps you want.