• Home
  • About
  • Resume

API keys for weather providers

By , 06/29/2016 5:00 PM

Many apps and watchfaces for Pebble smartwatch provide weather information and many of them require you to have your own key, unique for each weather provider. Here’s how to obtain API keys for 3 major most popular weather providers:

  1. For Forecast.io register at https://developer.forecast.io/ – and at the very bottom of the page there will be long string of letters an numbers – that’s the key.
  2. For OpenWeatherMap register at https://home.openweathermap.org/api_keys and you will see a form create your API key there
  3. For WeatherUnderground go to https://www.wunderground.com/weather/api, click LOGIN button, fill the form to create account, go to “Key Settings” in menu and generate your API key there

It is *highly* recommended once you get your keys – save them at https://www.pmkey.xyz service. Then all you have to remember to get them is simple 5-digit pin and more and more watchfaces (CobbleStyle 2 being one of them) use this service for easy key retrieval.

Full control of your Limitless LED/Milight bulbs from Amazon Echo

By , 05/12/2016 11:34 AM

Limitless LED Limitless LED offers full color RGBW light bulbs that you can control over Wi-Fi/4G from your computer, phone or smartwatch. They’re an inexpensive alternative to Philips Hue and they look really cool.
But I, being lazy ass that I am, was wondering if you can control the lights from Amazon Echo by voice commands alone. Out of the box Echo and Limitless LED don’t recognize each other. Amazon can see and control Hue, but not Limitless LED. Fortunately geniuses of BWS Systems came up with a really cool piece of software – home automation bridge “HA-Bridge”. It’s free and written in Java so it can run pretty much in any environment under any OS. What it does – it emulates Philips Hue API so other devices on your network – like Echo – can see and interact with it. Continue reading 'Full control of your Limitless LED/Milight bulbs from Amazon Echo'»

Flicker-Free IFRAME refresh

By , 05/05/2016 3:05 PM

One of our projects consists of single parent page and “widgets” that display secondary (classic ASPX webform) pages. A recent feature request was to auto-refresh widget information at given intervals. On the surface it was pretty straghtforward:

<iframe id="xIfrWidget0"></iframe>
var ifr = document.getElementById('xIfrWidget');

setInterval(function () {
   ifr.src = 'widget.aspx';
}, 2000)

The problem with this approach – there’s an ugly flicker of white between page refresh and the goal was to keep displaying current IFRAME content up until refreshed content is ready. Yes, there’re various AJAX-ified methods (including ASP.NET UpdatePanel) – but they add unnecessary overhead and may cause other issues.

The solution was suggested by this Stack Overflow post. The idea is to have secondary, hidden IFRAME into which perform actual load. Once load complete – switch IFRAMES – currently visible with old content becomes hidden, and hidden one with new content becomes visible. It goes something like this: Continue reading 'Flicker-Free IFRAME refresh'»

Pebbles, rectangles and stack overflow

By , 04/20/2016 2:17 PM

UntitledWhile working on my Pebble watchface “Future Time” I have encountered persistent annoying problem – watchface would run for a while and then crash – and not only crash, but actually restart the watch. What made this even more frustrating – after 3 restarts in a row Pebble would revert to recovery mode and complete firmware reinstall was required (did I accidentally write a Pebble virus?).
When I dug into device logs I found out that every restart was given reason: “Dangerous Stack Overflow”. Which is kinda strange – I don’t have any recursions nor deeply nested function calls nor large local variables. I tried lots of things – including extreme ones like declaring all local function variables as global or static – nothing helped.
Finally Christian form Pebble developers forum shed a light. He pointed out that I use a lot of GRect constructs which is basic rectangle building block for pretty much anything from defining layers to graphics functions. I used GRect inline directly inside function calls, which I thought wasn’t a big deal, after all “everybody does that” – including Pebble in its examples. Well, as Christian pointed out those GRects are kind of local variables, and either memory is not reclaimed fast enough when they go out of scope or they spring memory leak.
Keeping this in mind I created a global GRect variable and when needed to use a GRect in local function, first I’d assign it’s value to the variable and then use variable in the function.
So something like this:

static void layer_update(Layer *layer, GContext *ctx) {
   graphics_draw_rect(ctx, GRect(10, 10, 30, 30));
   graphics_draw_bitmap_in_rect(ctx, bitmap, GRect(20, 20, 40, 40));

Becomes thus:

GRect temp_rect;

static void layer_update(Layer *layer, GContext *ctx) {
   temp_rect = GRect(10, 10, 30, 30);
   graphics_draw_rect(ctx, temp_rect);
   temp_rect = GRect(20, 20, 40, 40);
   graphics_draw_bitmap_in_rect(ctx, bitmap, temp_rect);

That’s it. This simple change cured the plague, no more crashes, restarts or recovery – just smooth sailing.

[Video] Cancel long running SQL Command in ASP.NET WebForm application

By , 04/01/2016 9:50 AM

A while back I wrote an article on how to Cancel long running SQL Command in ASP.NET WebForm application

Webucator ASP.NET training was kind enough to turn it into video-lesson. Enjoy!

Trump wants to bring Pebble home

By , 04/01/2016 12:01 AM

Trump on PebbleDonald Trump’s plan to “Make America great again!” would have you spending a whole lot more dough on your next Pebble smartwatch.

Not surprisingly, that would be the logical consequence of the Republican presidential front-runner’s latest ambitious promise: Getting Pebble to start manufacturing their products in the US instead of China.

“We’re going to get Pebble to build their damn watches in this country instead of in other countries” Trump said in a speech at a rally in Supai, Arizona.

The Donald’s claims are made to appeal to a voters having difficulties finding jobs in the US. Pebble, the world’s most innovative company with cult of followers, designs its best-selling Pebble Time, Pebble Time Steel and Pebble Time Round in the US but relies on partners in China and Chinese factory workers to assemble all of them. But what would be the price to build those “damn watches” in the US? Even a rough estimate of the basic costs shows it’s an unrealistic option, leading to a Pebble smartwatch with a potentially jaw-dropping price tag.

To keep things easy, let’s just observe salaries of workers occupied with assembling a Pebble. A labourer at Chinese manufacturing factory gets paid roughly $400 a month before overtime, according to the New York Post.

Now assume Pebble goes the cheaper route and utilizes a factory in Wyoming or Georgia, which happen to have the country’s lowest minimum wage at $5.75 an hour. Working 8 hours a day, 5 days a week, a US worker will earn $824 a month, or more than double the Chinese labourer. And if Pebble were to utilize someone in its home state of California, where the minimum wage is $9 an hour, the monthly pay is $1,400, or more than triple of the chineese.

And that’s ssuming you have number of workers with enough technological skills to do the job (and you don’t) and also assuming those workers will work for minimum wage (they will not). After awhile, things don’t add up.

While there are a number of other factors that go into a Pebble, including the components, shipping, marketing and research and development, doubling the labor costs could significantly hike up the price of a Pebble. Current price of Pebble Time is $150 — will you pay for the same smartwatch $300? $400? Or more?

“Twice the price is a very modet estimate” says Clara Mileshti, an analyst at Dumas CostEff, about the price hike of a Pebble if it were manufactured in the US.

In another speech, Trump proposed a 35 percent tax on products built outside of the US. So at a minimum, that would mean your next Pebble Time’s price could start at over $200.

Pebble declined to comment on Trump’s comments and didn’t want to get into the potential math of bringing watch manufacturing back the US.

Trump’s comments ignore the fact that Pebble does buy some of its components from US companies, including LEG’s Cortex-MI5 processors. The company said earlier that it believes it affects jobs creation in the US throug encouraging developers to learn and and create software for their appstore ecosystem. And by the way, creating and submitting an app to Pebble appstore is free for developers.

Pebble couldn’t afford to build a watch in the US at a reasonable price. Making a more costly, “Made in the USA” product is not an option, especially as consumers start to wise up about how much they’re spending on their smartwatches. Today Pebble is the leader in low-cost efficient watches. But alternatives are cropping up.

So strike it up as another crazy, wild claim by Trump. Or is it?

Unblock my heart, i mean, iPhone for Pebble geocoding

By , 03/29/2016 11:15 AM

Cobblestyle I’ve recently updated code for Cobblestyle Pebble Watchface to take advantage of very cool geocoding service called Nominatim by Open Street Maps.

Nominatim is used in two places: Direct lookup is used in watchface’s config page to lookup coordinates of a place by its name for custom location setting; reverse lookup is used to lookup location name by its coordinates to display name on actual watchface.

It was working fine – on Pebble watches connected to Android phones. It was failing miserably on iOS, so iPhone Pebble users were getting neither location nor weather updates. And it was pretty puzzling for a while until I obtained logs from running watchface thanks to invaluable help from Robin.

Turned out iPhone Pebble app was plain simple blocked by Nominatim service, every attempt to retreive location resulted in message being sent back “You have violated acceptable policy”. Which was kinda surprising since I just started using the service. When I contacted Nominatim support, they told me that apparently some Pebble app running from iPhone abused the service pretty badly, running hundreds of requests per second. And since the only way they can detect requesting app is by it’s User Agent string – all apps spotting iPhone Pebble UA were blocked.

Support suggested to set UA string specific to the app so it could be easily identifiable. Standard approach to set headers on xmlHttpRequest object is .setRequestHeader(..). Unfortunately by many browsers and clients it is considered unsafe to spoof UA via request headers. Fortunately iOS allows that, so all I have to do is catch and ignore erros in other clients. Basically this line of code solved the issue:

try {xhr.setRequestHeader("User-Agent", "Cobblestyle Pebble Watchface");} catch(e){}

Thanks to this as of version 2.19 Cobblestyle watchface correctly displays weather and location information. Yay.

TSQL ISNUMERIC and “String or binary data would be truncated” error

By , 02/17/2016 12:34 PM

If you’re using TSQL ISNUMERIC function in a query, e.g.


You may receive unexpected error:

String or binary data would be truncated.

ISNUMERIC must truncate string data, and if you experienced the above error, some of your data is over the limit. But you can augment the above query:


But cutting only 8000 chars you will avoid the error, and I seriously doubt you will have number over 8000 digits long so it’s a safe bet as well

Persistent configs in Rocky.js watchfaces

By , 02/09/2016 10:56 PM

Rocky.JS is the first step in Pebble journey to run JavaScript directly on the watches (unlike Pebble.JS which runs on your phone). Previously I described how to convert a simple watchface from C to Rocky.js. But that was a static watchface with unchangeable settings.

Here I will show how to create a configurable watchface in Rocky.js similarly how classic SDK faces can be configured. You will be able to reuse your existing config page – and if it was set to work with Pebble emulator as well as real watch – you will reuse it without any changes at all.

First let’s review how classic Pebble SDK calls config page. In PKJS (JavaScript) portion of Pebble code usually there’s a piece like this:

  function(e) {

If user requests config of face/app – this event fires and opens page with configurable options from specified URL. After user modifies settings usually “Save” button is clicked on that page and code similar to this executes:

$('#xbtnSave').click(function () {
   var location = (decodeURIComponent(getURLVariable('return_to')) || 
                   "pebblejs://close#") + 
   document.location = location;

Here, first we determine which location to redirect config page to. If parameter "return_to” is passed in query string (here custom function getURLVariable() is used to extract individual parameters – look it up), so if this parameter is passed – it means config page is called form the emulator and we use it for redirection. Otherwise we use standard "pebblejs://close#" URL to save settings into real watch. We also take settings object which has our collective options combined, convert it to string and add to the URL as a parameter. Page then is redirected to resulting URL and Pebble emulator or real watch takes care of processing parameters.

So, how can we (re)use it in a Rocky.js watchface? Continue reading 'Persistent configs in Rocky.js watchfaces'»

Rocky.js – Pebble watch coding in JavaScript

By , 02/08/2016 3:59 PM

Pebble never ceases to amaze. And every time you think – this is it, they reached the pinnacle of awesomeness – they surprise you again. This time they did pretty much the impossible – ported their C SDK to JavaScript, by creating Rocky.JS project. Ultimate goal is to run JS directly on the watch hardware – this will open way to huge number of new developers who hesitate to dive into depth of C. Meanwhile it provides ability to run Pebble code directly in a browser! It’s a lot of fun and as a bonus you can insert Pebble watchfaces directly into your website as evident by living watchface you see here.
Watchface you see running above is called Meyer Object it’s been available for Pebble watch for a while and I decided to port it to Rocky.JS Continue reading 'Rocky.js – Pebble watch coding in JavaScript'»

Panorama Theme by Themocracy