Cross origin in Sinatra

I keep looking this up, so:

require 'sinatra'
require 'sinatra/base'
require 'sinatra/cross_origin'

class MyApp < Sinatra::Base
  register Sinatra::CrossOrigin

  get '/' do
    cross_origin
    ...
  end

end

Notes on uploading images via sinatra in ruby

In case it’s useful to anyone else. I got tips via this post which has a snippet that allows you to see what files are open.

ObjectSpace.each_object(File) do |f|
  unless f.closed?
    puts "This file is still open: %s: %d\n" % [f.path, f.fileno]
  end
end

It turned out I was leaving my temporary file open. The upload code is from here.

post '/image' do
 cross_origin
  name = params[:name]
  my_file = params[:my_file]
  unless params[:my_file] && (tmpfile = params[:my_file][:tempfile])
    @error = "No file selected"
    return haml(:upload)
  end
  STDERR.puts "Uploading file, original name #{name}"
  directory = "public/data"
  path = File.join(directory, name+".jpg")
  File.open(path, 'wb') do |f|
    while chunk = tmpfile.read(65536)
      f.write(chunk)
    end
  tmpfile.close
  end
  "Upload complete\n"
 end

or more concisely (thanks @andrewn)


post '/image' do
 cross_origin
  name = params[:name]
  my_file = params[:my_file]
  unless params[:my_file] && (tmpfile = params[:my_file][:tempfile])
    @error = "No file selected"
    return haml(:upload)
  end
  STDERR.puts "Uploading file, original name #{name}"
  directory = "public/data"
  path = File.join(directory, name+".jpg")
  FileUtils.mv(tmpfile, path)
  "Upload complete\n"
 end

and on the other side, the curl command is:

curl http://example.com/image -F my_file=@"/run/shm/image.jpg" -F "name=new_name"

HP Cooltown notes

Last week, a tweet from @iotwatch pointed at a 14-year-old promo video for HP’s “Cooltown” project.

Perhaps this was Alex’s intention, but it actually stands up pretty well as a (somewhat cheesy) invocation of some actual usecases for IoT-type work for end users, which I reckon are largely missing (unlike the usecases from the corporate point of view where we gather all your data, or the smart city ones, where we gather all your data).

It prompted me to have a quick look at the site, now sadly defunct, having transitioned through something called “mobilebazar” to just a redirect to HP’s main site. Everything seems to be on archive.org; @timkindberg just pointed me to a cache elsewhere.

Here are a few rough notes. It relates quite closely to a number of things I’m working on, including an EU project, MediaScape and Radiodan. I’ll try and have more of a dig through at some point.

—-

People, places, things: web presence for the real world
Tim Kindberg, John Barton, Jeff Morgan, Gene Becker, Debbie Caswell, Philippe Debaty, Gita Gopal, Marcos Frid, Venky Krishnan, Howard Morris, John Schettino, Bill Serra

  • “Web presence is the representation of people, places and things on the web. It extends the “home page” concept to include all physical entities and to include deliberate and automatic system supported correlation of the home page or point of web presence with the physical entity”
  • three categories: people, places, and things
  • everything has a web server physically associated with it, either on it or near it (a ‘gateway’ machine)
  • user’s pda can access available services via multicast over the LAN or directly via beacons or tags (infrared or RFID), possibly with a layer of indirection
  • potential problem – how people create new point of Web presence
  • interacts using restful web services
  • “To deliver the convienence potentially available with wireless networks, it should be possible to connect devices to networks spontaneously, and have them function with little or no human intervention. This implies more than just automatic IP address allocation. It implies automatic service discovery and registration: the ability for devices to discover appropriate services, and the ability for devices (and other service providers) to register their availability without human intervention.”
  • “Real places don’t always match network topology, they can physically overlap, and they may have fuzzy boundaries.
  • “what is to be included in a place is also a matter of policy” <– contextual and access privilages
  • no discovery protocol is identified that meets the criteria
  • web redirection for people
  • secure tunnelling for accessing documents from company servers
  • “We need sensing and service discovery technologies to feed the Web with URLs.”

The Context Toolkit: Aiding the Development of Context-Enabled Applications
Daniel Salber, Anind K. Dey and Gregory D. Abowd

  • interesting approach to abstracting sensor information into small reusable components
  • “Context widgets can be composed to provide richer context information while reusing existing widgets. For example, composing the IdentityPresence and Activity widgets could provide a simple Meeting widget. By combining the information about the presence of people at a location and an estimate of their activity, one can roughly detect if the people are engaged in a meeting or if they are just sitting in the same place and no collaborative activity is taking place.”

A web-based nomadic computing system
Tim Kindberg and John Barton

  • practicalities of authoring: “The place master can initiate the place with a web-based form. The form processing can return a barcode to be printed and attached to her booth. She walks up to a series of objects with her PDA, reads their barcodes, and binds them in the new place.”
  • “One of the most difficult problems is rendezvous (presence-tying)”… tell it the url of the place; or, search for a known ip printed on it; or has a prestent id on the web
    direct content post “The only agreement we need between sources and sinks is the format of the data”… “The format of this introductory or “meta-” data has to be widely agreed upon and stable over time; our approach is to use an ASCII encoded XML format carried in a MIME entity”
  • “We should also allow “content-negotiation”, that is the source and sink should be able to exchange information on the formats they support to select a common and appropriate one”
  • “Indirect content post” (a link rather than direct transfer)
  • settings: “For example, we can have the camera issue a GET to the printer’s web server and have the printer return an XML or HTML form listing the possible options. Once the camera user has selected the settings, the new settings and the image can be transferred to the printer”

Semantic Location
Salil Pradhan

  • Semantic location – physical location represented by a uri – may help with privacy concerns

W3C Web of Things workshop cheat sheet

(Thank you @philarcher1 for the much better title).

I’ve had a look through the submissions for the W3C Web of Things workshop being held next week in Berlin. I have to confess that if I had realised there were over 100 submissions I might not have started this, but anyway, here’s my personal summary.

Webiness / Internet of Things crossover seems to have manifested itself in three ways

  • Semantic web / linked data
  • Restful apis for sensors
  • HTML-based cloud platforms for programming and controlling sensors, virtualising platforms.

A large number of the papers are about Semantic Web / Linked Data projects and EU-funded projects in both the IoT and SemWeb areas. There is a fair bit of interest in existing standards, as you’d expect (there are rather a lot of those – one paper has a massive list). A little bit of interest from organisations involved in business-orientated platforms and systems. Quite a few manufacturers, Samsung, Sony, Cannon, LG etc. One utility company (EDF). Quite a few phone network companies. A couple of programming environments.

Not many usecases at all. Two terrifying ideas. Very little discussion of security, privacy and the potential for annoyingness. I thought this and this were interesting as papers. Riot-os and node-red look interesting.

Topics / areas / types of organisation:

  • Existing mobile companies – 6
  • Existing semantic web – 8
  • EU / national research projects – 15
  • Existing (vaguely?) related platforms –  9
  • Small web firms – 1
  • Existing IoT-type standards, consortia – 6
  • Application of other standards to IoT (XML, EXI, NSD API, json, Atom, streaming protocols, social web, javascript, WebRTC, human capabilities) –  6
  • Existing embedded systems – 5
  • Interesting ideas – 2
  • Terrifying ideas – 2
  • Manfacturing etc – 3
  • Device manufacturers – 7
  • Privacy, security – 4
  • Usecases ~ 7
  • Virtualisng platforms ~ 6
  • Utility company – 1

Technologies and standards: CoAP, MQTT, 6lowpan, NSD API, DDS (OMG?) “Cyber-Physical”, IETF Javascript Object Signing and Encryption (JOSE), efficient RDF, EXI, GS1

Usecases: refuse, traffic management, home temperature sensing, health and wellbeing, advertising

One line summary of each submission

Holger Reinhardt, Layer 7 Technologies, a CA company – APIs and SOA, mobile

Michael Mrissa, LIRIS CNRS / IUT Lyon 1 – French national funded project for appliances on the web

Dave Conway-Jones, IBM UK Labs – node-red – hobbyist open-source visual tool for wiring the Internet of Things

Jacek Chmielewski, Ubliko – SME with adaptive UI cloud platform looking to move into IoT

Haythum A. Osman, SoftPlus Limited – small web design / business networks

Amelie Gyrard, EURECOM – Mobile Communications Dept. – “Semantic Web of Things (SWoT)” coming from the semantic web area, arguing that there is a need for web of things technologies to share their ontologies.

Eric Kauz, Director Data Systems, GS1 – An existing standard for RFID tag identifiers “GS1″. Mention of linked data.

Richard Mark Soley, Industrial Internet Consortium and Object Management Group – New Internet of Things, Machine-to-Machine, Cyber-Physical Systems consortium

Thomas Scheerbarth, Deutsche Telekom - interested in standards

Thomas Amberg, Yaler.net – NAT traversal system

Kemal A. Delic, HP – Resilience of IoT Systems

Mingqiu Sun, Intel – Embedded systems

Romain Bellessort, Canon Research France – Interested in network discovery api

Yusuke DOI, Toshiba – Resiliance – XML – compact XML

Charles Silver, Algebraix Data Corp – own triple store

Don Arnstein, MITRE Corp

Stefan Lüder et al., Siemens – Suggests a new activity around perhaps, json, xml, atom, streaming protocols, social web.

Mathias Herberts, Cityzen Data – platform for managing sensor data

Ricardo Morin, Intel – Interesting ideas, genuine knowledge of constrained devices, interested in devices acting together, javascript frameworks.

Jonathan Ding, Intel – javascript and IoT interests

Satoru Takagi, KDDI – interested in WoT and html5 and commonjs

Arnaud Braud, Orange – outlining some questions particularly for mobile phone network operations in the new regime

Shigeru Owada, Sony CSL – Pub-sub and restful Android middleware application for home appliances and sensors.

Jon Nordby and Henri Bergius, Flowhub – kickstarted funded visual programming IDE (like node-red?)

Josiane Xavier Parreira, INSIGHT Centre for Data Analytics, National University of Ireland, Galway - Outline of a researcher’s expertise in linked data for mobile

Cuno Pfister, Oberon microsystems AG – expertise and software for IoT and sensor systems, cloud-based, includes android and .NET frameworks

Masaki Umejima, Smart House and Building Committee, Japan Smart Community Alliance - Description of ECHONET Lite an interface for heating control in Japan. Interests in interoperable interfaces and security.

Andreas Harth, Karlsruhe Institute of Technology – Rule-based linked data for shared state systems for iot.

Dong-Young Lee, LG Electronics – Challenges for finding lightweight web-friendly tech

Marko Vujasinovic, INNOVA S.p.A. - The management of trust and trust negotiation for the Web of Things marketplaces – semantics, EU project.

Markus Isomäki, Nokia (co-written with Teemu Savolainen and Art Barstow) – Discussion of existing standards, knowledge of existing work, low-power devices. bridging low-power and the web. CoAP, service discovery, apis, linking low-power devices and the web, interesting

Monika Solanki, Operations and Information Management Group, Aston Business School, Aston University – Complex supply-chain logistcs usecase. Linked data, EU project

Kensaku Komatsu, NTT – An autonomous communication system based on NSD and WebRTC relay. discovery apis.

Carlos A Velasco, Fraunhofer Institute for Applied Information Technology FIT – Modelling user preferences for accessibility.

Benoit Herard, Orange – Sensonet – sensors linked to a backbone by sms; applications in Africa

Marcello Missiroli, Department of Engineering, University of Modena & Reggio Emilia. – Usecases showing some problematic privacy applications

Sharad Garg, Intel – interoperable educational devices

Lionel Médini, University of Lyon – Linked data service architecture for robots

Vagner Diniz, W3C Brazil Office – “currently designing a project on real-time garbage tracking”

Robin Berjon, W3C – web standards stalwart

Pablo Chacin, SenseFields – traffic management solutions based on wireless sensor networks

Bernard Gidon, W3C

Gregor Schiele, Insight Centre for Data Analytics, National University of Ireland, Galway – researcher in linked data, mobile, EU projects

Pedro Reboredo and Bartosz Korajda, Bosch Rexroth AG – manufacturing process control company

Claes Nilsson, Sony – On the programme committee

Laurent Tonnelier, mobiLead – Mobile marketing company

Natasha Rooney, GSMA

Saumitra Mukherjee, Professor of Geology Remote sensing and Space Sciences School of Environmental Sciences, Jawaharlal Nehru University

Erik Albers, Free Software Foundation Europe – labeling system, privacy

Harry Halpin, W3C – web crypto

Kia Teymourian, Institut fuer Informatik, Freie Universitaet Berlin

Chakib Bekara, Researcher in Computer Science, Network, Security and Multimedia Team, TELECOM Research Division, Center for Development of Advanced Technologies, Baba Hassen – Research project on IoT and energy

Youngsun Ryu, Samsung Electronics – smart home protocol. Interoperability of legacy and new things. all aspects of wot / iot, incl UX etc

Alejandro Llaves, Ontology Engineering Group (OEG), Facultad de Informática, Universidad Politécnica de Madrid – RDF stream processing

Phil Archer, W3C Data Activity Lead – Description of various standards in w3c and elsewhere about the web of data

Oliver Pfaff, Siemens AG, Corporate Technology, Research & Technology Center – general auth patterns

Christian Prehofer & Luca Chiarabini, fortiss GmbH – General comparison of mashup and modelling tools

Angelo Corsaro, CTO PrismTech and OMG Architectural Board, OMG DDS SIG Co-Chair -Promo for  http://www.omg.org/spec/DDS/Current

Roger Menday, Fujitsu Laboratories of Europe, London – linked data, rest, http

Charles Eckel, Cisco Systems – Managing network traffic securely

Mme Kheira Bekara, Equipe Réseaux et Systèmes d’Information, Division Architecture Systèmes et Multimédia, Centre de Développement des Technologies Avancées (CDTA) – CoAP, constrained devices and bandwidth, compression

B. Helena Rodriguez, Shopedia SAS – “the WoT for Fashion Shopping Apps” a fashion application; usecases; objects?

Redouane Boumghar, Co-Founder Dacteev, Intelligent Embedded Systems and Robotics – ambient intelligence. reasoning etc. privacy. advertising

Pete Rai, Technical Leader, Cisco – SPVSS – considers annoying objects. argues for capabilities over ontologies. agents protecting users

Milan Milenkovic, Intel Corporation, Internet of Things Group – argues for open, interoperable sensor data

Kosuke Nagano, ACCESS company – browser based software to consumer electronics devices

Tariq Samad, Corporate Fellow, Honeywell Automation and Control Solutions, President, American Automatic Control Council, Editor-in-Chief, IEEE Press – usecases and research issues from business

Dominique Guinard, Vlad Trifa EVRYTHNG Ltd, UK and Co-founders @ Webofthings.org – labelling, human-friendly WoT

Nick Allott, UbiApps and webinos foundation – Webinos project

Athanasios Karapantelakis, Ericsson – EU project, semantics, smart city

Prabhakr Srinivasan, Video Technology Group (SPVTG) of Cisco – frightening proposal for connecting up humans to the TV to feed them advertising

Jan Mendling, ​Institute for Information Business, Vienna University of Economics and Business – EU projects, semantics, logistics, RDF stream processing

Michael J. Koster, ARM – IETF CoRE (Constrained RESTful Environments)

Matthias Kovatsch, ETH Zurich – CoAP demos. Inspecting devices via browsers

John Mattsson, Göran Selander and Göran AP Eriksson, Ericsson Research – security architecture, constrained environments, existing standards

Danh Le Phuoc, Insight Centre for Data Analytics, National University of Ireland, Galway – RDF and sensors

Kazuo Kajimoto, Cloud Solution Center, Panasonic Corporation – cloud for managing IoT devices

Jean-Paul Calbimonte, EPFL – RDF stream processing

Alécio Binotto, IBM Research – Brazil – health usecases

Hyojin Park, Korea Advanced Institute of Science and Technology – virtualised objects

Brian Ratcliff, Your Internet of Everything – open standards for web-based orchestration

Janina Sajka, Linux Foundation & Michael Cooper, Shadi Abou-Zahra, W3C Web Accessibility Initiative – usecases for accessibility in the IoT

Yongmin Jung, ETRI – virtualisation platform for home sensors. Tracking

Ryuichi Matsukura, Fujitsu – virtualisation platform for home sensors. Tracking

Walter Waterfield, Software AG – RDF streams, EU project

Björn Brecht, Kieback&Peter GmbH & Co. KG – “manufacture automation and efficiency hardware, software”

Roland Gueye, EDF – electricity-related usecases and general interest

Martin Schäffler, Bosch

Charalampos Doukas, CREATE-NET – EU project, restful apis for sensors

Robert Kleinfeld, Fraunhofer FOKUS – Research Institute for Open Communication Systems – SOA researcher

Rohit Pasam, Xaptum – IoT startup

Jens Haupert, DFKI – research project

Laurent-Walter Goix, et al., Telecom Italia – EU project, modelling IoT things as social objects

George Arriola, Monohm Inc. – proposals for standards approach

Joerg Heuer et al., Siemens – outline of various usecases and standards (including XMPP XEI, efficient RDF)

Mike Bergman, Consumer Electronics Association (CEA) – would like to talk about standards activity at CEA

Stefano Marzani, DQuid – “easy application development for connected objects” – a dev board.

Nicholas M Barry, Boeing – interesting usecase, briefly discussed (planes)

Marc Benhaïm, GS1 – “I am the new person in charge of web of things at GS1 France.”

Emmanuel Baccelli, INRIA – “The friendly Operating System for the Internet of Things”

Meng Chee & Gene Becker, Samsung – service composition, REST, “Everyware”

Adrian Paschke, Department of Mathematics and Computer Science, Freie Universitaet Berlin – RuleML researcher

Kent Spaulding & Reza B’Far, Oracle – “Employee Wellness product”

Jonghong Jeon, Minkyo In, Seungyun Lee, Protocol Engineering Center, ETRI – IoT and related standards

Chromecast setup

Chromecasts are £40-odd quid on Amazon.co.uk, and we’re interested in using them at work, so I got one to look at. Here are the bits you get in the box:

Chromecast pieces form the box

And here’s a walk through of the setup using Mac OS X (10.8.4) and a Samsung 6000-series TV.

Overall – the setup was a bit longer and more involved then I’d anticipated, and it’s not really clear what’s going on, unless like me you’re working with a device that does more or less the same thing. The setup worked almost perfectly though and the result is impressive.

The way the setup works is that the device broadcasts a wifi network, you connect to it after some visual checking (it does the connecting automatically via an app), and then you tell it your wifi connection details – the app gathers the names of wifi networks but you tell it the password. We are doing the same thing in a manual way in Radiodan and the Arduino Yún does something similar. My colleague reports that it is smoother on an Android app, and I guess Apple laptops probably are not the key target devices, since the functionality is like Airplay.

You need to install an app for the setup and an extension in Chrome to ‘cast’ things; for YouTube and a few other sites you cast directly in the page, which as I understand it, makes the Chromecast device make a separate call to the site for the best version of the video. For other things you just get the whole browser tab, including fullscreen if you like. The Chromecast extension can

  • access your data on all websites
  • access your tabs and browsing activity
  • manage network connections

Not sure what those mean precisely yet.

You don’t have to be logged into Google to set it up or use it, and I wasn’t.

Here are the instructions:

Chromecast box - instructions

You put the chromecast into the HDMI socket and plug it into the mains via a mini USB. Flip through sources on the TV and find the screen that looks like this:

Chromecast set me up screen on the TV

At this point we spotted a new wifi network, ‘Chromecast4827′.

On the computer (Mac OS X) you go to the Chromecast setup link and download and install an app:

Mac OS X screenshot of Chromecast installation app

When you run it it asks you to say which Chromecast you are installing – I forgot to take a screenshot of that bit.

Then the app is obviously connecting to the wifi network. The twee ‘Back in a snap’ makes me want to lightly punch someone, but that’s all part of the current infestation of corporate cutesiness, so I guess I have to live with it.

Screenshot of app connecting the Chromecast to the wifi network

I didn’t have to change the input, this code just appeared…

Screenshot of app showing the code

…on the TV:

The code on the TV

Then you wait a while for it to download software and restart.

Chromecast on the TV downloading updatesScreenshot of app explaining that the Chromecast is downloading updates

TV says ‘ready to cast':

TV says ready to cast

‘Continue’ on the app, then we get ‘start using chromecast':

App success screen

‘Start using Chromecast’ takes you to a link in Chrome.

‘Hang in there’ *light punch*

Link to extension in Chrome

Google Cast extension wants to know your brain:

Google Cast extension permissions requested

Once the extension was installed, I watched the ‘how to’ video locally –

Chromecast how-to video

- then tried to play it remotely – it didn’t work.

A different YouTube video worked, though it grumbled when I pressed the extensions ‘cast’ button and prefered me to use the one in the YouTube page:

YouTube video - suggesting use of the in-page buttonYouTube video working on the TV

The nice thing about doing it like this is you can open a new tab locally and it carries on playing.

iPlayer worked by casting using the extension – in full screen it looked pretty good:

iPlayer on Chromecast

- although in full screen you can’t open another tab.