Sending data from Lantronix to Google Analytics

Google and Lantronix

The following is a copy of a guest post from Kurt Busch, CEO, and Mariano Goluboff, Principal Field Applications Engineer at Lantronix as originally posted on Google’s corporate blog at: http://analytics.blogspot.com/2014/03/sending-data-from-lantronix-to-google.html

Background

Google Analytics makes it easy to create custom dashboards to present data in the format that most helps to drive business processes. We’ve put together a solution that will make several of our devices (networking and remote access devices) easily configurable to enable delivery of end device data to Google Analytics. We use the Lantronix PremierWave family of devices to connect to an end device via a serial port like RS-232/485, or Ethernet, intelligently extract useful data, and send it to Google Analytics for use in M2M applications.

What you need

To get started, grab the Pyserial module, and load it on your Lantronix PremierWave XC HSPA+. You’ll also want a device with a serial port that sends data you want to connect to Google Analytics. A digital scale like the 349KLX is a good choice.

Architecture overview

With the Measurement Protocol, part of Universal Analytics, it is now possible to connect data from more than web browsers to Analytics.

Lantronix integrated the Measurement Protocol by using an easy to deploy Python script. By being able to natively execute Python on PremierWave and xSenso devices, Lantronix makes it very easy to deploy intelligent applications leveraging Python’s ease of programming and extensive libraries.

The demonstration consists of a scale with an RS-232 output, connected to a Lantronix PremierWave XC HSPA+. The Python script running on the PremierWave XC HSPA+ parses the data from the scale, and sends the weight received to Google Analytics, where it can then be displayed.

The hardware setup is show in the picture below.

The technical details

The Python program demonstrated by Lantronix uses the Pyserial module to parse this data. The serial port is easily initialized with Pyserial:

class ser349klx:
# setup the serial port. Pass the device as '/dev/ttyS1' or '/dev/ttyS2' for
# serial port 1 and 2 (respectively) in PremierWave EN or XC HSPA+
def __init__(self, device, weight, ga):
  while True:
   try:
    serstat = True
    ser = serial.Serial(device,2400, interCharTimeout=0.2, timeout=1)
   except Exception:
    serstat = False
   if serstat:
    break
    
  self.ser = ser
  self.weight = weight
  self.ga = ga

The scale used constantly sends the current weight via the RS-232 port, with each value separated by a carriage return:

def receive_line(self):
  buffer = ''

  while True:
   buffer = buffer + self.ser.read(self.ser.inWaiting())
   if '\r' in buffer:
    lines = buffer.split('\r')
    return lines[-2]

The code that finds a new weight is called from a loop, which then waits for 10 equal non-zero values to wait for the weight to settle before sending it to Google Analytics, as shown below:

# This runs a continuous loop listening for lines coming from the
# serial port and processing them.
def getData(self):
  count = 0
  prev = 0.0
  #print self.ser.interCharTimeout
  while True:
   time.sleep(0.1)
   try:
    val = self.receive_line()
    weight.value=float(val[-5:])*0.166
    if (prev == weight.value):
     count += 1
     if (count == 10) and (str(prev) != '0.0'):
      self.ga.send("{:.2f}".format(prev))
    else:
     count = 0
     prev = weight.value
   except Exception:
    pass

Since the Google Analytics Measurement Protocol uses standard HTTP requests to send data from devices other than web browsers, the ga.send method is easily implemented using the Python urllib and urllib2 modules, as seen below:

class gaConnect:
def __init__(self, tracking, mac):
  self.tracking = tracking
  self.mac = mac
 
 def send(self, data):
  values = { 'v' : '1',
     'tid' : self.tracking,
     'cid' : self.mac,
     't' : 'event',
     'ec' : 'scale',
     'ea' : 'weight',
     'el' : data }
 
 res = urllib2.urlopen(urllib2.Request("http://www.google-analytics.com/collect",
                                        urllib.urlencode(values)))

The last piece is to initialize get a Google Analytics connect object to connect to the user’s Analytics account:

ga = gaConnect("UA-XXXX-Y", dev.mac)

The MAC address of the PremierWave device is used to send unique information from each device.

Results

With these pieces put together, it’s quick and easy to get data from the device to Google Analytics, and then use the extensive custom reporting and modeling that is available to view the data. For example, see the screenshot below of real-time events:

Using Lantronix hardware, you can connect your serial devices or analog sensors to the network via Ethernet, Wi-Fi, or Cellular. Using Python and the Google Analytics Measurement Protocol, the data can be quickly and easily added to your custom Google Analytics reports and dashboards for use in business intelligence and reporting.

Lantronix + dweet + freeboard: Connecting a microcontroller’s serial port to the Internet of Things

XPico Wi-Fi Freescale Tower ModuleTalking to my customers, everybody is asking about the Internet of Things. There is so much information about the IoT, that it can be confusing to figure out how to solve your specific business problem with all the options available.

Where the rubber meets the road is putting hardware, software, and services together to get to a cogent solution. All while reducing costs and time to market, of course. So when I heard someone wanting to connect to Bug Labs’ dweet.io I was intrigued. Here’s a service that claims to make the sending of data very easy. I don’t even have to sign up for a free account, I can just start sending data from my device? Let’s try this out.

I took a Lantronix xPico Wi-Fi Freescale Tower System connected with a Kinetis microcontroller. The xPico Wi-Fi manages the TCP connection to the dweet.io server, so the microcontroller only needs to construct the message to be sent. The dweet.io platform accepts data with standard HTTP requests, so the microcontroller just sends the following data to the UART port, and the rest is taken care of by the xPico Wi-Fi.

GET /dweet/for/<uid>?potentiometer=<value> HTTP/1.1\r\n
Host: dweet.io\r\n
Connection: keep-alive\r\n
Accept: */*\r\n
\r\n

The program running on the microcontroller sends new data any time that the potentiometer on the Kinetis Tower board changes. This video shows how it works:

http://youtu.be/xmrgD9j_iFA

Using freeboard.io, it couldn’t have been easier to view the information being posted. In literally 5 minutes, I had a dashboard that shows current and historical data:

Conclusion

There are many services and products to help get your device connected to the Cloud. Lantronix hardware and the software applications that run on it make it very easy to connect your device to the network. The dweet.io and freeboard.io services from Bug Labs can take the data from the device and make it actionable quickly.

Figuring out how to use the Internet of Things to your advantage doesn’t have to be complicated. We can help you design and implement a total solution of hardware, software, and services to meet your needs.

xPrintServer: On the Road, Online, On TV, and In Print

Launching a new product is never easy, and it can even be more challenging when the product is one of a kind. It takes creativity, out of the box thinking, lots of elbow grease, a little bit of luck and persistence.

Little more than a year after its launch, you’d be hard pressed to find an iPad or iPhone enthusiast who has not heard about xPrintServer. While this product line – and the market opportunity for networked mobile printing– is in many ways still in its infancy, xPrintServer is well positioned to capitalize on the need for a cost-effective and easy to deploy networked mobile printing solution as more and more businesses adopt iPads in the workplace.

Our latest marketing blitz hit the market back in early November 2012, in preparation for holiday gift guides and promotions.

Lantronix and the xPrintServer were featured in more than a dozen national morning show segments on NBC, CBS, ABC, CNBC and more – thanks to Steve Greenberg, author of Gadget Nation and host of the TV show “Invention Hunters.”  From Chicago, Minneapolis, and Washington, to New York, Seattle, and Houston, the gadget-shows were seen by mobile Apple device users nationwide!

Tech Guru Steve Greenburg showcases the Lantronix xPrintServer (WFAA - Dallas / Fort Worth)

Key to holiday marketing success are “holiday gift guides” – and xPrintServer proved to be a popular stocking stuffer this year.  From British Airways in-flight magazine (Business Life) to Electronic House’s Back to School Cool list to Cult of Mac’s iPad Lover’s Gift Guides, we appeared in more than a dozen magazine and online guides. The result was that in the December quarter, Lantronix recorded increased sales in our device management product category – most of the growth in sales due to the xPrintServer product’s growing popularity.

Holiday Gift Guides and xPrintServer

Following our success formula from last year, we once again leveraged CES and MacWorld as platforms for launching and promoting the xPrintServer.  Prior to the events, we demonstrated the xPrintServer (Office and Home editions) to more than 1,000 members of the U.S. and EMEA press.   To complement the resulting hundreds of pieces of press coverage and product reviews, we also hit the market with print and online ads, building momentum for the live events.   MacWorld, iPhoneLife, MacDirectory, iBusiness Magazine, Network World,  and more all featured one to two page print ads – distributed and mailed to more than 2 million iPad and iPhone enthusiasts – from on-site distribution at CES and MacWorld, to newsstands, airports and electronics stores nationwide.  Not to be outdone by the xPrintServer, our president and CEO Kurt Busch and the Lantronix M2M story made the cover and feature story in EEWeb’s latest Pulse Magazine.

i.Business Magazine + Legacy Series Special Edition

To complement the on and off line print ads, the Lantronix xPrintServer took to social media.  Our award-winning “I Can Print!” commercials have been aired on CNBC and Google’s online network of video sites, on YouTube, and even made it to a premier showing during Fashion Week in Toronto.  To further capture gadget and trend influencers, xPrintServer is being featured on the new OraTV channel – exposing the brand to more than 1 million viewers in March and April of 2013.   No online or social media effort would be complete without the endorsement of technology guru Leo Laporte (go to minute marker 16.00) and his team’s support of the xPrintServer, which was highlighted on several dozen TWiT.TV podcasts over the past six months.

OraTV and Leo Laporte / TWiT.TV feature xPrintServer

The marketing campaigns laid the groundwork for MacWorld – which many show registrants and exhibitors said should be called “Lantronix World”!   We were the official mobile print sponsor – you couldn’t enter or exit the show without seeing or hearing about the xPrintServer, thanks to some aggressive field sales and marketing, complete with Lantronix-branded “I Can Print!” gear.

MacWorld Photos

In addition to winning “Editor’s Choice” by The Mac Observer for the second year in a row, one of the most exciting aspects of MacWorld this year was the emphasis on Apple products serving the B2B market.  Our own chief technology architect, Dave Wagstaff, presented “Best Practices for Deploying Mobile Print Solutions in the Enterprise” to an audience of nearly 100 IT executives.

Kurt Busch accepts TMO's "Editors Choice" Award

As we move into 2013 and beyond, more of our focus will be on leveraging the brand awareness we’ve built to drive enterprise adoption of the xPrintServer family.   The upcoming iBusiness Magazine road shows  should prove to drive awareness and sales into the small business market.  iBusiness has been a big supporter of the xPrintServer, and given the excitement and interest from their audience, our new xPrintServer Office Edition was featured on the magazine’s holiday edition cover — with more than 500,000 copies distriuted at CES and MacWorld.   We will also be partnering with targeting publications such as CIO Magazine, Network World, InfoWorld, Control Design, and more, to continue direct marketing to key decision makers and influencers for all of Lantronix’ M2M products, services and solutions.

For real-time updates on what Lantronix is up and where we’ll be, please check back regularly, and if you haven’t already done so, sign up to receive our newsletters, tweets, and more.

Students Across the Country: “We Can Print!”

Since the launch of xPrintServer-Network Edition back in December, we’ve seen tremendous demand from educational institutions, school districts, students, parents, and educators themselves.  The rapid pace of iPad deployment in schools – from kindergarten (yes, kindergarten) through college and graduate school – has only been outstripped by the students’ ability to embrace any piece of new technology, especially the iPad.   [The Cult of Mac recently posted a great article about how iPads are transforming the classroom.]

Lantronix at Mater Dei's back-to-school week

Lantronix’ Dean Lazzara demos the xPrintServer during Mater Dei’s back-to-school week.

The Lantronix team has been actively working with schools to print-enable their campuses, in preparation for back-to-school initiatives.  Probably the most interesting insight we’ve gleaned so far is that these schools are a near perfect microcosm of large enterprises.  They boast a wide variety of user types (students, teachers, administrators, visitors) – some of who are friendly, some are hostile/hackers. But in the end, every student and parent with whom we’ve spoken has said the same thing – “Thank you for helping us print!”  Clearly the market is now catching up to the pain-point we’ve solved with the xPrintServer.

One of the schools with which we’ve most recently been working is Mater Dei High School in Orange County, California.  Last year, this leading national high school rolled out more than 2,000 iPads to the student body – one of the first schools in the country to build out a curriculum leveraging the iPad platform.  In addition to working to print-enable their campus for the coming school year, they’ve also been part of our new back-to-school marketing promotion – the goal of which is simple: Get the xPrintServer into the hands of students – one of the most coveted segments, given their powerful word-of-mouth opportunities and profile of being early adopters.

Whether schools use the iPad for engaging students, conducting online classes, or simply as replacements for text books, the fact is, iPads are changing the way we educate our children, and what better validation for our xPrintServer than to hear a student say, “My Dad just bought one of those for us so we can print, and it’s so cool!”

Lights, Camera, xPrintServer!

On Monday, March 19th, xPrintServer made its television debut – and we’re happy to report, the audience loved it.  Even the anchor and technology reporter cheered as the xPrintServer did exactly what it’s supposed to do – PRINT!

Earlier this year at CES, we had the pleasure of meeting Bruce Pechman, “The Muscleman of Technology.”  For anyone who hasn’t met or seen Bruce, he’s an incredibly enthusiastic, seasoned on-air talent with over 300 live TV appearances reviewing technology and healthcare products.  He appears regularly on Los Angeles superstation KTLA (10 million household reach) and “Good Morning San Diego.”  After providing a live demo of our xPrintServer for Bruce at CES, he invited us down for an on-air product review.

The day started early – 3am to be exact.  By 5:30am, we were ready for our close-up.  San Diego-based KUSI-TV was already in full swing, reporting the morning news, and Bruce was wide awake and ready to go (I don’t think this guy sleeps!).   Check out the entire video for Bruce’s review of the new iPad and the xPrintServer. (Click on “Bruce appears on KUSI-TV: The new Apple iPad” video 3/19/12)

The KUSI-TV studios in San Diego, CA.

The KUSI-TV studios in San Diego, CA.

Bruce Pechman and the xPrintServer

Bruce Pechman and the xPrintServer

Of course, we’re thrilled about the brand awareness and extended publicity reach afforded to us by a live television spot, but something that never gets old is watching the reaction from customers and the press when they see the product work.  Responses typically begin with disbelief that the xPrintServer is plug-and-print… followed by near jubilation at the mere fact you can print from your iPad or iPhone.   And finally, a “Wow – it’s THAT simple?!”    This is either a referendum on how poorly most products are made today – or a testament to how important it is to create and market a product that delivers on what the customer wants.  In our case, we’re happy to report it’s the latter.

xPrintServer: The pre-commercial teaser.

xPrintServer: The pre-commercial teaser.

Bruce Pechman and Mark Tullio

Bruce Pechman and Mark Tullio

Thanks again to Bruce and the KUSI-TV family for having invited Lantronix on the show, and look forward to working with them as we continue to build brand awareness for Lantronix, the xPrintServer, and other products to come.