When Salesforce is life!

Tag: Heroku

[Salesforce / IoT] Let’s play the game with Salesforce IoT (part 3): Heroku IoT platform

 

In the previous post we have setup everything needed on the Salesforce side to configure the IoT Explorer.

Before jumping on the Arduino Nutellator 3000 project, we have to create a proxy that will transform data received from the devices in order to push them to our beloved CRM.

For those, like me, who are the typical TL;DR developers, head over the GitHub repository and have a look at this simple NodeJS project.

What do we need?

  • A Salesforce Connected App
  • An Heroku dyno to host the proxy (our own IoT Platform)
  • An Heroku Postgres Database (free tire) to handle basic authentication

What will this app do?

The main job of this app is to create Platform Events filled with the data that comes from the Nutellators and send this events to the IoT Explorer to finally trigger the orchestrations.

N.B. If the last sentence is totally obscure to you, please go back to the first post of this series to learn more about Platform Events and how they are related to Salesforce IoT.

Configure a connected app on the CRM

To send a Platform Event using the REST APIs, you’ll need a Connected App.

To create a new one go to Setup > Apps > Connected Apps and create a new app:

We won’t be needing the callback URL since (so put a protocol://fake formatted url) we’ll be using Username-Password OAuth Flow (more details here).

From this app you need the following info to properly configure the Heroku app:

Next thing you need your user’s username/password/token to complete the Oauth process.

Setup Heroku

Create a new Heroku app (let’s say iot-nutellator.herokuapp.com).
Fork the salesforce-iot-nutellator-proxy repository on GitHub.

Click on the Deploy tab and link the forked Github repository:

Do not deploy the code right now.

Add the Heroku Postgres add-on and set everything up

Jump to the Resources tab and look for Heroku Postgres addon (choose the free tier):

Let’s put some settings

Before deploying the code from GitHub we have to setup few settings on the Settings tab:

You should have seen the DATABASE_URL already there: this is the url to access the Postgres database.

Deploy

Go back to the Deploy page and hit the Deploy branch button:

Last action to make is executing the DB initialization code that creates a iot_user table with a single user called “user” with password” pass: this user (and any other you decide to add) will be used to authorize every request from the device using basic authentication.

To execute the script simply use the Heroku console:

Test it out!

Open the app on your browser using https://your-app-name.herokuapp.com.
If everything is ok you should see this message:

Salesforce IoT Proxy 
© Enrico Murru - blog.enree.co 2018

Anatomy of the proxy

The Express JS server exposes 2 different routes:

  • GET /: doesn’t actually do anything
  • POST /api/level: this is the route used by the devices to send their data

A typical call would be so formatted:

POST /api/level

Headers
Authorization: BASIC BASE64(user:pass)
Content-Type: application/json

Body
{
    "level": 30,
    "device_id": "T1-C0DE-IRI"
}

Where device_id is the Devide Id that we’ve seen in the Nutellator Salesforce object and level is the nutell-level of the device in %.

The result of such a call is an update triggered by the orchestration on the targeted device:

In the next and last post we’ll be closing the post series by having fun with Arduino and a Nutellator 3000 project.

[Chrome Extension] “Pack your link” extension on the store by enree.co (yes, thet’s me…)

a{ color: red !important;}

I’m not a marketing guy, I neither have requested advices from my marketing guys friends…I did it all my way and that’s why my brand new Chrome Extension will be forgotten in days!

Let’s start from the beginning…

Once upon a time there was a simple Chrome Extension I made at work for WebResults, my Company: you will hear about it in weeks, but not now.

After weeks of testing we decided to put it in the market but I didn’t now how to do it (I know, there si plenty of stuff online, but I don’t trust myself till I see things done!…that’s why because sometimes I behave like Goofy when dealing with simple tasks!!).

So I thought, “How can I do a clean job for my company without making foolish mistakes”?

The answer was “Create your own extension”.

That’s why I created url.enree.co (I love this domain name), a simple Url packing utility hosted on Heroku, written in NodeJS.

Why not creating a simple chrome extension to use this service?

Here you are Pack your link by url.enree.co.

Publishing a Chrome Extension on the store is really easy.

  1. Create your extension (start here if you don’t know what to do, it’s easy and fun)
  2. Go to the Chrome Store Developer dashboard: you have to pay 5$ to be able to publish your creations on the store, once in a lifetime! In few minutes you’ll be allowed to publish extensions and apps.
  3. ZIP your local extension’s folder and upload it: it seems that you cannot remove a product once uploaded (read more details here, but I’m not quite sure about it), but you can still unpublish to hide it.

See ya!

[Github / Maven] Maven repository using GitHub

This simple post is a reminder on how to create a Maven2 repository and use it with Maven in a “pom.xml” file or in Java Play!. The first step is to create a GitHub Repository (it will be named “maven2”).Then reproduce the folder structure of a Maven Repository, as I did in my “Maven2” repo (https://github.com/enreeco/maven2).For instance, given this artifact (jar):

<groupId>com.rubenlaguna</groupId>
  <artifactId>evernote-api</artifactId>
  <name>Official Evernote API</name>
  <version>1.22</version>

Create these folders:

./com
     ./com/rubenlaguna
     ./com/rubenlaguna/evernote-api
     ./com/rubenlaguna/evernote-api/1.22
     ./com/rubenlaguna/evernote-api/1.22/evernote-api-1.22.jar
     ./com/rubenlaguna/evernote-api/1.22/evernote-api-1.22.pom

Now you have a pubblicly accessible Maven2 repository at https://github.com/[username]/[repoName]/raw/master/ (in my case https://github.com/enreeco/maven2/raw/master/).To consume it in your projects, just add this lines in the “pom.xml” file of your project:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.echoservice</groupId>
    <version>1.0-SNAPSHOT</version>
    <artifactId>echoservlet</artifactId>
    <repositories>
    <repository>
      <id>myRepository</id>
      <url>https://github.com/enreeco/maven2/raw/master/</url>
    </repository>
    </repositories>
    <dependencies>
 . . .
 </depencencies>
 . . .
</project>

To integrate the maven repo in a Java Play! project (necessary if you’re messing with Heroku), take the “/prject/Build.scala” file and add those lines:

import sbt._
import Keys._
import PlayProject._

object ApplicationBuild extends Build {

    val appName         = "evernote-integration"
    val appVersion      = "0.1"

    val appDependencies = Seq(
      "com.rubenlaguna" % "evernote-api" % "1.22", //Evernote Thrift Library
      "com.rubenlaguna" % "libthrift" % "1.0-SNAPSHOT",//Thrift core library
      "postgresql" % "postgresql" % "9.1-901.jdbc4", //Postgres
      "org.apache.httpcomponents" % "fluent-hc" % "4.2.1" //Apache HTTP client
    )

    val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings(
     resolvers+= "personal maven repo" at "https://github.com/enreeco/maven2/raw/master/"
    )

}

Maven will search for the selected jars in the default locations, but when it’s not finding anything it will search for your personal resolvers.

Powered by WordPress & Theme by Anders Norén