Skip to main content


Showing posts from December, 2012

Simple TCP client server sockets application using IPv6 and IPv6

So here is a pair of programs demonstrating the use of sockets on Linux. The server program is run first. Then whenever the client program is run, it connects to the server on the specified port and they both exchange strings and terminate. TCP is used over IPv4.
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <netdb.h>#include <arpa/inet.h>void error(char*msg){perror(msg);exit(1);}intmain(int argc,char*argv[]){int sockfd, newsockfd, portno; socklen_t clilen;char buffer[256];struct sockaddr_in serv_addr, cli_addr;int n;if(argc <2){fprintf(stderr,"Usage: %s\n", argv[0]);exit(0);}printf("\nIPv4 TCP Server Started...\n");//Sockets Layer Call: socket() sockfd =socket(AF_INET, SOCK_STREAM,0);if(sockfd <0) error("ERROR opening socket"); bzero((char*)&…

Script for uploading DHT11 readings to Cosm using Curl/JSON on Raspberry Pi running Arch Linux

Earlier, I have written on how to get the Vodafone 3G USB Modem (K3770-Z) working on Raspberry Pi here. After I was done doing that, I decided to create a shell script to upload sensor data from DHT11 to over the internet connection provided by the Vodafone 3G USB Modem.

Here are is how I got that done:
NOTE:  Execute all commands on Raspberry Pi unless otherwise specified. I referred to the following two Adafruit tutorials while doing this: DHT Humidity Sensing on Raspberry Pi with GDocs Logging and end Raspberry Pi Data to COSM

Assemble the setup as shown in the photo above and follow the instructions here (Getting Vodafone 3G to work on Raspberry Pi in India using K3770-Z) to get the Vodafone 3G USB Modem working on your Raspberry Pi. I use the Arch Linux distribution. Make sure to create sakis3g.conf to automate the Sakis3G script. Also ensure that the sakis3g script is in your root's home directory (/root) and has the execute bit set before your proceed. Your Raspber…

Visio and Word files misbehaving with GitHub

All GitHub repositories are initialized with a default .gitattributes file which has the following configuration to handle Microsoft Word files:

*.doc diff=astextplain *.DOC diff=astextplain *.docx diff=astextplain *.DOCX diff=astextplain
This configuration works fine as long as the Word files in your repositories have only text and tables. The moment you try to commit Word files with images embedded in them or Microsoft Visio files, the line ending conversion and diff applied to them by Git will probably corrupt them. The files will open properly on your computer, but if you try to clone the repository on a different computer and try to open those files you will probably encounter the following messages:
To fix this we need to add/modify the following lines in the .gitattributes files present in that particular repository (if you are using GitHub for Windows, you can do this easily by selecting Options>Settings... for that particular repository):

*.doc binary
*.DOC binary
*.docx binary

Getting Vodafone 3G to work on Raspberry Pi in India using K3770-Z

I live in Pune, India and I wanted to do this: DHT Humidity Sensing on Raspberry Pi with GDocs Logging

So I assembled this:

and faced two problems: 

I couldn't immediately figure out how to get K3770-Z to work on Raspberry Pi. Since this K3770-Z 3G USB Modem from Vodafone worked on Ubuntu 12.10 x86 without requiring any installation or configuration, I was sure that I could somehow get it to work on Raspberry PiWhen I finally did get the modem to work on RPi, I found that the iBall Portable Charger (Datasheet here) could not source the peak current requirements of the modem when it turns on registers to the 3G network. The charger can supply only 600mA @ 5V where as the 3G modem definitely requires a lot more during registration.The second problem can be solved simply by using a 12V 2.2Ah Sealed Lead Acid Battery and a 12V to 5V DC-DC converter. For the conversion you could use the car accessory for charging phones or build one yourself using LM2576.

As for the K3770-Z, here is how I …