HTTP Server for uCLinux

You may need a web server on your no-MMU embedded system in order to allow remote configuration or possibly provide external access to some files. Usually, you’ll need a lightweight webserver (e.g. not Apache) with the required features and in case of no-mmu system, source that can accommodates uClinux limitations such as no fork support. You’ll also take into account the programming language or the server: e.g. C/C++. Java, Ruby, Perl… If your system does not support Java or Perl for example, that may not be the best solution to add one of those only for the web server and it also depends on the resources (Flash/RAM) available. There are plenty of C/C++ lightweight http servers such as thttpd or lighttpd, however those are using fork in their code. One open source http server that is lightweight and uses vfork (instead of fork) is mathopd. At the time of writing, […]

Languages, Unicode and Charset

If your application needs to support multiple languages or if it needs to support languages with different character sets such as simplified Chinese (GB2312, GBK, GB18030, HZ,..) or traditional Chinese(BIG5, HKSCS, EUC-TW) you’ll need to make yourself familiar with Unicode and the different character sets. In this article, we’ll focus on introducing character sets,  manipulating and converting charsets and the possible challenges you may encounter while handling Unicode text files. If you plan to support multiple languages, you’ll also have to internationalize your application, for example by using Po files for different languages, a Po file editor and possibly have the translations done in launchpad if your project is open source. But this would be another subject. Go for Unicode If you are building a new application make sure its structure is based on Unicode (UTF-8, UCS-2, UTF-16 or UTF-32 ) since those charsets can handle most written languages (UTF: […]

Linux Scripts to find Public IP Address

In some cases, you may need to know your public IP or the public IP of a server behind a NAT (e.g. for remote SSH login) if the IP is assigned dynamically as is the case for PPPoE connections. Here are several ways to find your public IP in Linux using the shell. 1. Using curl (almost too simple) curl -s http://www.whatismyip.org 2. Using wget wget -q -O – checkip.dyndns.org|sed -e ‘s/.*Current IP Address: //’ -e ‘s/<.*$//’ 3. Using lynx lynx -dump checkip.dyndns.org If you have access to a web browser, you can simply use http://www.whatismyip.org, http://checkip.dyndns.org or http://www.moanmyip.com. Jean-Luc Aufranc (CNXSoft)Jean-Luc started CNX Software in 2010 as a part-time endeavor, before quitting his job as a software engineering manager, and starting to write daily news, and reviews full time later in 2011. www.cnx-software.com

USB Hotplug Parameters and A Simple Linux USB Hotplug Script

USB Hotplug allows your system to detect a USB device has been inserted or removed and perform certain actions upon the USB device detection. The article below is largely inspired by http://linux-hotplug.sourceforge.net/?selected=hotplug which does not seem to work anymore. USB hotplugging involves: MODULE_DEVICE_TABLE support in the USB Device Driver API, so that a driver’s probe() routine is called only when it’s very likely to want to bind to a particular interface. USB always uses this. Support for invoking the hotplug helper (/sbin/hotplug by default) when devices are added or removed. This functionality is enabled only by CONFIG_HOTPLUG. That hotplug helper usually contacts a policy agent which handles the USB-level configuration or activation tasks appropriate to this device and the current system configuration. Boot-time configuration (“cold-plugging”) can be managed by the /etc/rc.d/init.d/hotplug startup script, if the “usbmodules” command line utility is available. (There is also a “diet hotplug” tool for use […]

Socket Programming: Client crashes when exiting server

One of our digital signage applications was crashing when the control server was shutdown at the same time a command was sent with no apparent reason. It would always crash inside the write function (see code below) and no error message were returned. sent = write(fd, buf, n); After a while, we found that in case the connection with the server is lost, and write tries to access the server, it will generate a SIGPIPE signal and in most systems, the application would just exit by default. A simple way to handle this case was to ignore the pipe signal by adding the following line during initialization: signal(SIGPIPE, SIG_IGN); In case the server is down at the time the write function is called, the signal SIGPIPE would be ignored, write would return -1 and errno should return 32 (Broken pipe). Alternatively, if needs be you could also handle the SIGPIPE […]

Finding a device IP Address

If you are developing software for an Ethernet (or Wifi) device, you’ll need to access the board for debugging and/or testing purpose. If your board does not have user interface or the serial port is not available, you’ll have to find the IP address (assuming it is using DHCP) before accessing the board thru telnet or ssh. A simple way to do that is to ping the broadcast address and check the arp table. > ping -b 192.168.0.255 WARNING: pinging broadcast address PING 192.168.0.255 (192.168.0.255) 56(84) bytes of data. 64 bytes from 192.168.0.246: icmp_seq=0 ttl=64 time=0.018 ms 64 bytes from 192.168.0.101: icmp_seq=0 ttl=64 time=0.217 ms (DUP!) 64 bytes from 192.168.0.246: icmp_seq=1 ttl=64 time=0.023 ms > arp -i eth0 arp -i eth1 Address                  HWtype  HWaddress           Flags Mask            Iface 192.168.0.103            ether   00:50:FC:00:00:01   C                     eth1 192.168.0.109            ether   00:13:20:01:01:01   C                     eth1 If you cannot find your device, it may be configured to […]

How to check open files for a process

While debugging your program, you may encounter the message “Too many open files”. One way to fix the issue could be to review your code and check open, fopen, socket and pipe calls are matched with close and fclose calls, but with large projects this may be cumbersome. A better way is to list the open files using the proc filesystem. I’ll use VirtualBox program as an example since this is running in our server. First, locate the process ID (PID): pgrep VirtualBox 3901 3950 Then list the file descriptor opened for process 3901 sudo ls -l /proc/3901/fd total 0 lrwx—— 1 root root 64 2010-10-05 14:52 0 -> /dev/pts/1 lrwx—— 1 root root 64 2010-10-05 14:52 1 -> /dev/pts/1 lr-x—— 1 root root 64 2010-10-05 14:52 10 -> pipe:[15825] l-wx—— 1 root root 64 2010-10-05 14:52 11 -> pipe:[15825] lr-x—— 1 root root 64 2010-10-05 14:52 12 -> pipe:[15829] […]

List the dynamic libraries used by a program

In order to know which dynamic libraries a particular binary is using, just type ldd. For example with busybox: sh-3.00# ldd /bin/busybox /bin/busybox: is setuid libcrypt.so.0 => /lib/libcrypt.so.0 (0x2aaed000) libm.so.0 => /lib/libm.so.0 (0x2ab41000) libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x2ab9c000) libc.so.0 => /lib/libc.so.0 (0x2abeb000) ld-uClibc.so.0 => /lib/ld-uClibc.so.0 (0x2aaa8000) Jean-Luc Aufranc (CNXSoft)Jean-Luc started CNX Software in 2010 as a part-time endeavor, before quitting his job as a software engineering manager, and starting to write daily news, and reviews full time later in 2011. www.cnx-software.com

EDATEC Raspberry Pi 5 fanless case