Archive

Archive for the ‘Programming stuff’ Category

Gboard: Arduino-compatible board with integrated GSM/GPRS

February 11th, 2013 No comments

With my recent work (aka pet project) on embedded systems mainly based on Arduino I finally came across an Arduino board with built-in GSM/GPRS connectivity. Getting an Arduino with an GSM/GPRS shield is pretty straight forward, but if the device is meant to be strong and durable, these shields don’t feel good.

Itead’s Gboard does. And it is also pretty cheap; definitely cheaper than e.g. the ordinary Arduino Uno with a GSM/GPRS shield from Seeedstudio.

However. The Gboard is “Arduino-compatible” and as such I was expecting a few hiccups to get it up and running. And as usual a few turns quickly into a lot. So let’s have a look.

Jumpers

Like most communication boards the GSM chips is connected through a serial port. But the Gboard just like the Arduino Uno only has one. And this one is also used for programming purpose. In order to use both programming and GSM connection, make sure jumpers are set to ST-D2 and SR-D3 (‘Software UART to SIM900, Hardware UART to Specific’).

Programming connection

Just like the Arduino Ethernet board (and others) the Gboard doesn’t have its own USB connection. So a ‘FTDI-style basic USB-to-serial board’ is required. But unfortunately the ones from Adafruit or Sparkfun don’t work out of the box. First you need to be careful as the boards from Arduino itself require 5 Volts. But the FTDI connection on the Gboard only takes 3.3 Volts. Don’t mix this up! Additionally the wires aren’t compatible. It seems best to spend the few additional dollars to get the dedicated FOCA board from Itead. But of course this removes the fun of tinkering and I wanted to reuse my existing programming board. Connecting GND, DTR, TX, and RX with dedicated wires does the trick (I had to swap the TX and RX connections). In order to power up the board either a 3.3V connection is required, or simply remove the VCC connection at all and power the Gboard through an external power supply.

External power source

If you need to test the GSM features, make sure you have an external power source connected. Just because the lights go on with a FTDI connection doesn’t make the GSM chip work.

Digital ports

The connections of the Gboard differ quite a bit from the default Arduino layout. In particular the board doesn’t list any digital ports; just connections labeled with A0 to A7. But in the Arduino world the first 6 analog ports can be used as digital ones as well. Address them by starting from digital pin 14 for A0. The interface on the Arduino is called ‘Electronic brick interface’ and it seems to be used in other boards as well. So there are pre-made 3 pin connections with sensors available. But as long as you connect +, -, and Signal in the proper way, most other sensors will work too.

Arduino IDE

I assume other options might work as well, but for me the board ‘Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328′ and Programmer ‘Arduino as ISP’ did the trick. Sometimes an upload to the board fails, but most often a single repeat will be successful.

If it still doesn’t work, consider this trick by pressing the Arduino RST button at the right point in time.

GSM/GPRS features

Finally there is a dedicated lib to ease the use of the GSM chip. I assume sending AT command straight to the soft serial port will work as well, but I haven’t tried it. But even though the lib claims it is compatible with the Arduino 1.x IDE, it didn’t work in my environment. I had to do a couple of tweaks to the lib (but I don’t remember every single step). Steps like removing newsoftserial from lib folder and adding ‘#include ‘ in GSM_Shield.cpp.

Driver hiccups

Sometimes, especially under Windows it seems as if the wrong drivers are taken for the FTDI communication. Check here to see get an idea of the correct ones. Note that installing the correct driver might fail as a wrong one is somehow blocking it. Follow FTDIs uninstall instructions and try re-installing the driver again.

Categories: Programming stuff

Freaking Ruby implicit return values interferes with Rails ActiveRecord callbacks

October 25th, 2012 Comments off

I just need to rant that (again) I run into a problem with unexpected side-effects of the usually neat feature of implicit return values in Ruby. This (although not really obvious) feature always returns the value of the last executed statement in a method as a return value. But this isn’t always as obvious as it sounds. This can cause strange side-effects.

As an example take the Rails callbacks for ActiveRecord. These callbacks like :before_create are typically used to handle data validation. Thus if they return ‘false’, the process to save the record is canceled.

But now instead of validation you want to ensure that certain other attributes are automatically set depending on other attributes; maybe even boolean attributes like in this block:

class Message < ActiveRecord::Base
  belongs_to :probe
  attr_accessible :probe_id, :value1, :value2, :probe_enabled

  before_create :set_probe_enabled
  
private
  def set_probe_enabled
    self.probe_enabled = self.probe.enabled?
    true # if only this would have been obvious...
  end  
end

Here we simply want to set the boolean attribute enabled? depending on the value of the enabled attribute of the associated probe. Obviously the probe.enabled? can either return true or false. Unfortunately in case of false the whole statement ‘ self.probe_enabled = self.probe.enabled?’ returns false. And if this is the last statement being executed, the whole method will return false. And a false in such a callback will cancel the creation of the object…

Take-away lesson: Pay attention to implicit return values especially in Rails ActiveRecord callback methods when dealing with boolean values.

Your very own SMS – Internet gateway with Arduino

October 9th, 2012 No comments

There are plenty of SMS services on the web to link SMS and the Web together. However especially if you need a local SMS number in an unsupported country like Malawi or simply want to DIY, then this Arduino-based solution might be your right choice. For sure you could also go big-scale with your own full-blown SMS gateway like Kannel. But where is the tinkering fun?

Combining an Arduino Uno, a GSM/GPRS shield like the one from Seeedstudio, and an Ethernet shield is all you need besides a SIM card. Now simply stack everything together and upload this Sketch.

Process incoming SMS
Depending on your requirements you might want to modify the code. E.g. one obvious case would be an SMS-to-Email forwarder, but for the typically free email service like gmail.com the Arduino lacks resources and power to process their TLS/SSL security. But other ways are possible. The code is already prepared to post an incoming text message right into a Google Spreadsheet with a way described on open-electronics. Or you could notify your own web app with a custom HTTP request. Or simply forward the incoming text message to another mobile number. Or what else can you think of?

As the SoftwareSerial library is used the code also inherits its default buffer size of 64 bytes. Not too much even in the context of SMS. Better patch the Arduino code (argh!) and increase it to something like 128 bytes as I’ve done. Still not the full size of a SMS, but enough for my purpose. Carefully check the documentation – it can save you days!

Process incoming HTTP requests
For the opposite way of sending text messages to mobile phones from the Internet you could use a provider specific solution. E.g. some (many?) providers offer email addresses like @smsmail.eplus.de. Every incoming mail is forwarded to the corresponding text phone as a text message. Just check if you can find information about your specific provider. But in case where your provider doesn’t provide this solution, or you need to find a generic way across different providers, or you want to do it via HTTP requests rather than emails, this Arduino Sketch can also be used.

As the sketch will run a little local HTTP server, you might need to change the current IP (192.168.1.177) to fit your needs. Once the system is available in the local network you can use a simple HTTP post to send out a text message, e.g. with curl:

curl --data "number=&message=innovative message" 192.168.1.177/sendsms

Of course you should protect the access to it as otherwise you might invite hitchhikers to misuse your airtime.

Feel free to have a look and use this code the way you want.

Note that the code uses the SimpleTimer library so make sure this is installed locally first.

Categories: Programming stuff

Calculate MySQL database size

July 8th, 2011 Comments off

Not sure anymore where I found this, but this is a nice script to see which MySQL tables take how much space.

SELECT NOW(), VERSION();
# Per Schema Queries
SET @schema = IFNULL(@schema,DATABASE());
# One Line Schema Summary
SELECT table_schema,
 SUM(data_length+index_length)/1024/1024 AS total_mb,
 SUM(data_length)/1024/1024 AS data_mb,
 SUM(index_length)/1024/1024 AS index_mb,
 COUNT(*) AS tables,
 CURDATE() AS today
FROM information_schema.tables
WHERE table_schema=@schema
GROUP BY table_schema;
# Schema Engine/Collation Summary
SELECT table_schema,engine,table_collation,
 COUNT(*) AS tables
FROM information_schema.tables
WHERE table_schema=@schema
GROUP BY table_schema,engine,table_collation;
# Schema Table Usage
SELECT table_schema,table_name,engine,row_format, table_rows, avg_row_length,
 (data_length+index_length)/1024/1024 as total_mb, 
 (data_length)/1024/1024 as data_mb, 
 (index_length)/1024/1024 as index_mb,
 CURDATE() AS today
FROM information_schema.tables 
WHERE table_schema=@schema
ORDER BY 7 DESC;
# Schema Table BLOB/TEXT Usage
select table_schema,table_name,column_name,data_type 
from information_schema.columns 
where table_schema= @schema
and ( data_type LIKE '%TEXT' OR data_type like '%BLOB');
set @schema = NULL;
Categories: Programming stuff

ERb’in “ActionMailer fixtures” Up

June 16th, 2009 Comments off

I don’t know if my slightly outdated Rails 2.2.2 is the problem. But unlike in the fixtures for normal unit tests, I can’t use ERb for my ActionMailers templates.

Add this method to your ActionMailer::TestCase to let ERb pre-process your fixtures:

  def read_fixture(action)
    a = super
    template = ERB.new(a.join)
    template.result(binding)
  end

Outlook-iPhone birthday synchronisation

May 30th, 2009 2 comments
  • Not satisfied with the way Outlook (2003) handles birthdays and anniversaries?
  • Want to have multiple birthdays just for one contact entry (maybe because you have one contact for a family, but want to track the birthdays of the countless kids)?
  • Do you need to control the reminders for the birthdays?
  • Wish you had the classical Palm solution (Feiertage) for your iPhone or iPod touch?

Yippee! Macro time – (again)!

LegeGeburtstageUndJahrestageImKalendarAn

Add multiple birthdays to the notes of your contact and create proper recurrent events. Basically enter for every birthday you want to track for this contact in a new line with the format GEB Name: 24.12.2000 (Note the European style date format day.month.year and the prefix GEB (german abbreviation for Geburtstag = birthday)). Simply add all of your birthdays or anniversaries to your contacts, run the macro, and of you go. For more details see the linked docu.

LoescheGeburtstageUndJahresTageImKalendar()

Remove all (automatically) created recurrent events (e.g. for cleanup purpose)

And if your Outlook asks you for every single modification for allowance, use Advanced Security for Outlook to suppress those questions.

Read more…

Categories: Programming stuff

Testing Webapps with multiple browsers

May 13th, 2009 1 comment

Developing web applications can be fun and hard almost at the same time.

But when it comes down to testing, it can be a .

Sure every developer has his favorite environment and develops against it. But his special browser is just a part of the big picture and there are way to many different browsers and versions out there in the wild. Of course you know them all:

  • Internet Explorer [ 6 | 7 | 8 with Compatibility View | 8 ]
  • FireFox [2 | 3 ]
  • Safari [ 3 | 4 ]
  • Chrome
  • Opera

And those are only the traditional desktop browsers for MacOS, Win and Linux. (Personally I assume, that one browser behaves almost the same on different OS when it comes to the programming model. But this is not necessarily true for layout issues). Note that this list totally ignores the growing mobile market. I don’t know yet how to deal with them…

It will get even ridiculous if you could only install one version of a browser at the same time. Yes, IE – most credits go to you! There are some hacks out there to install the Internet Explorer in different versions on one system.

In the past I’ve simply virtualized my system and got one image for every single browser. Worked, but it always felt like “shooting cannons to sparrows“. There is quite some overhead involved to install and actually fire up the VM image.

Why not simply virtualize the browser? That’s exactly what Xenocode is doing. Download, run and test. Nice. The seamlessly network integration even make those things like local proxy servers work.

Develop with Firefox

May 11th, 2009 Comments off

What is your favorite environment to develop new web applications?

Currently I think there is no way around good ol’ Firefox. Not because of the browser, but more because of all those addons. It took me some time to find my configuration. Here it is:

But too bad, I’m too lazy to describe them all. Anyway you have to get comfortable with your own list. What’s on it?

Categories: Programming stuff

Swap Lastname with Firstname in Outlook

May 1st, 2009 Comments off

Even my [ of course way too old, grandpa-style, ugly, quite unsexy, and nothing close to a nerd gadget ] mobile phone Nokia 6230 offers a PC sync. OK. They were supposed to offer this even in the last millennium. But ever since then I was struggling with it. Not even with a real day-to-day sync but just with a one-time copy operation of my contacts from my PC to the phone. Surely, if I only had/have a Mac. But life is never easy and you should always challenge yourself…

But why on earth is Nokia only offering one entry for a combined name field. In digits: 1, in letters again: ONE. But even more why on earth am at least I not able to put my Outlook contacts in the “Lastname Firstname” order to the phone. The PC Suite seems just to know it better and doesn’t let me. Therefore an alphabetic sort on the phone just shows of all the firstnames first. Crap and I need another solution.

So as I’m a developer I was refusing to simply look for already working solutions or even spend money. I had to do it the do-it-yourself way (for sure hundreds must have done this before).

So here is a small Outlook macro which takes all of your entries in the address book and places them in a new outlook address book called NokiaAddressBook. There it simply swaps lastname with firstname and I get my “Lastname Firstname” style. Stupid ugly, but also stupid simple.

Too bad my Nokia broke recently and now I switched to a Sony Ericsson.

PS1: This solution was heavily influenced. Thanks!
PS2: If you do the sync, close the Nokia Phone browser as it seems to block to connection of the PC Suite to your phone.
PS3: The Nokia Phone Browser supports an import/export of vCards. But (not surprisingly) Outlook does not. Another but: The standard windows address reads vCards. So import vCards first to the Windows addressbook and from there to Outlook…

Categories: Programming stuff

Network (HTTP) speed simulator

April 23rd, 2009 Comments off

If you’re seriously developing a webapp, sooner than later one of your clients will come with some Internet Explorer 6 related complains. Still in 2009, the year of the IE Death march. So what to do if they say: With IE6 is takes 3x longer to load the page than with _any other browser_?

But even if it is not the IE6, you still might wonder how your app behaves with different connection speeds. There are some (windows) applications out there, which try to simulate different network connections. There must be others, but I’ve found Netlimiter and Speed Simulator as out-of-the-box solutions. But Netlimiter is not free and Speed Simulator seems to have some problems with certain requests (AJAX, forwards, … who knows).

When it comes to HTTP-related things, why not using Squid as the de-facto standard for Proxy Servers?

Installing Squid is not as difficult as it may sound, even under Windows. Just make sure that the Delayed Pools Feature is enabled.

For your personal development you can leave all of the default configs in the squid.conf, except those:

  1. # allow all requests
    acl all src 0.0.0.0/0.0.0.0
    http_access allow all
    icp_access allow all
  1. # delayed pools
    delay_pools 1
    delay_class 1 1
    delay_access 1 allow all
    delay_parameters 1 4000/4000
    # 64000 = 64 kbytes = 512 kbits
    #  8000 =  8 kbytes =  64 kbits
    #  4000 =  4 kbytes =  32 kbits

To change the connection speed, simply tweak the values for delay_parameters e.g. to 64000/64000.

And if your are using Firefox as one of your development browsers, simply install the SwitchProxy Addon. This allows you to quickly switch between preconfigured proxy settings on-the-fly.

[And if you really what to go "pro", set-up multiple instances of Squid with different connection speeds, provide their services under different ports, and create different proxy configs for SwitchProxy. Then you don't even have to modify the squid.conf every time you want to switch the speed.]

Categories: Programming stuff