One of the great aspects of ThingWorx is the ability to connect disparate data silos to a central IoT hub. Many of these silos are made accessible through Web APIs. RESTful Web APIs enable developers to pull data from an inexhaustible number of sources around the web; often using nothing but a HTTP URI. Salesforce has an extensive REST API that can be accessed through ThingWorx. This blog will introduce you to creating a “Connected App” on Salesforce, authentication using username and password in ThingWorx, adding records to Salesforce, and finally modifying records. For a detailed description of Salesforce’s REST API, visit https://developer.salesforce.com/page/REST_API

Step 1 (Optional): Obtain a Developer Environment with Salesforce.com

If you do not already have a Salesforce account, navigate to https://developer.salesforce.com/platform/force.com and sign up for a free developer environment. It only takes a few minutes and you get a fully functioning Salesforce instance that you can freely develop in.

Step 2: Obtain a Security Token

You’ll need a security token to authenticate with a username and password. If you don’t already have one, or can’t dig it up from previous emails, you’ll need to reset the token.

Resetting the Token

1.    In the upper right-hand corner of your Salesforce page, click on your name and select “My Settings”

2.    On the left-hand menu, select “Personal”

3.    Under “Personal,” select “Reset My Security Token”

4.    Follow the directions on the page and you will receive a new security token via email

Step 3: Create a Connected App

To use the REST API, we’ll need to create a connected app that gives us a “Consumer Key” and a “Consumer Secret”.

Creating the Connected App

1.    Click on “Settings” in the upper right of your Salesforce screen

2.    On the left side, navigate to “Build” > “Create” > “Apps”

3.    Under the “Connected Apps” section, select “New”

4.    Fill out the fields as shown below. A callback URL is required but we won’t really be referencing it anywhere in ThingWorx. There is a great article on using Postman to test out REST calls with Salesforce at https://blog.mkorman.uk/using-postman-to-explore-salesforce-restful-web-services/ . The callback URL is used in the examples when authenticating in Postman.

5.    Click “Save.” You will get an alert that your connected app will take 2-10 minutes to take effect.

6.    After you click “Save,” you’ll see the “Consumer Key” and “Consumer Secret.” Copy those somewhere to use in ThingWorx.

Step 4: Authenticate Salesforce Session in ThingWorx

In this step, we’ll create a service in ThingWorx that returns a JSON for us to use in our other Salesforce requests.

1.    Create a service inside your Thing called AuthenticateSalesForce. I have a “TestThing” that I’ve created where I can try out new services without disrupting any of my live projects.

2.    Choose the “STRING” type for the result output, no inputs are needed unless you want to have the end user input their username and password. After we test functionality, we’ll change the output type to “JSON”

3.    Enter the following code, which is just the POST JSON function in the ContentLoaderFunction resource.

var params = {

                 proxyScheme: undefined /* STRING */,
                 headers: undefined /* JSON */,
                 ignoreSSLErrors: undefined /* BOOLEAN */,
                 useNTLM: undefined /* BOOLEAN *
                 workstation: undefined /* STRING */,
                 useProxy: undefined /* BOOLEAN */,
                 withCookies: undefined /* BOOLEAN */,
                 proxyHost: undefined /* STRING */,

url: "https://login.salesforce.com/services/oauth2/token?grant_type=password&client_id=&client_secret=&username= &password=" /* STRING */,

                 content: undefined /* JSON */,
                 timeout: undefined /* NUMBER */,
                 proxyPort: undefined /* INTEGER */,
                 password: undefined /* STRING */,
                 domain: undefined /* STRING */,
                 username: undefined /* STRING */

};

// result: JSON
var j = Resources["ContentLoaderFunctions"].PostJSON(params);

var result = j.access_token;

4.    Enter the consumer key, consumer secret, username (use %40 for the ‘@’ symbol), and password plus security token (enter your password and security token with no spaces between the two)

5.    Select “Done” on your service, save your Thing, and test the service. You should receive a session token like the one seen below:

6.    If nothing shows up, either the Salesforce server hasn’t activated the app, or there may be an issue with the URL. If you copy and paste the URL into PostMan, you should get an error message that clarifies the issue.

7.    When you’re getting an access token as the result, edit your service, change the result type to “JSON,” delete the last line (the “var result = j.access_token” line”), and modify the end of the service to now read:

// result: JSON

var result = Resources[“ContentLoaderFunctions”].PostJSON(params);

Step 5: Create a record in Salesforce

In this step, we’ll create a new account within salesforce using our new authentication service and a REST call utilizing the ContentLoaderFunctions.

1.    Create another new service in your Thing and call it AddSalesForceAccount. 2.    Create an input and call it AccountName. The type is “STRING” 3.    Type in the following code:

var authJSON = me.AuthenticateSalesForce();

var token = authJSON.access_token;
var instance_url = authJSON.instance_url;

var url = instance_url + "/services/data/v20.0/sobjects/Account/";

var authString = "Bearer " + token;
var headers = {
   "authorization" : authString,
   "content-type" : "application/json"
};

var content = {
 "Name" : AccountName
};

var params = {
                 proxyScheme: undefined /* STRING */,
                 headers: headers /* JSON */,
                 ignoreSSLErrors: undefined /* BOOLEAN */,
                 useNTLM: undefined /* BOOLEAN */,
                 workstation: undefined /* STRING */,
                 useProxy: undefined /* BOOLEAN */,
                 withCookies: undefined /* BOOLEAN */,
                 proxyHost: undefined /* STRING */,
   url: url /* STRING */,
                 content: content /* JSON */,
                 timeout: undefined /* NUMBER */,
                 proxyPort: undefined /* INTEGER */,
                 password: undefined /* STRING */,
                 domain: undefined /* STRING */,
                 username: undefined /* STRING */
};

// result: JSON
var result = Resources["ContentLoaderFunctions"].PostJSON(params);

4. Test the service. Enter a unique account name and verify that it shows up in Salesforce.

Step 6: Retrieve a Record ID

To modify a record, the record ID must be used to reference the object of interest. We can make a request to Salesforce to return relevant records using an SOQL query. This example will cover retrieving the record ID of the account we just created in the last step.

1.    Create a new service in your Thing

2.    Create an input and call it AccountName. The type is “STRING”

3.    Type in the following code:

var authJSON = me.AuthenticateSalesForce();


var token = authJSON.access_token;
var instance_url = authJSON.instance_url;

var url = instance_url + "/services/data/v20.0/query/?q=SELECT+name+FROM+Account+WHERE+name+=+'" + AccountName + "'";

var authString = "Bearer " + token;
var headers = {
   "authorization" : authString,
   "content-type" : "application/json"
};




var params = {
                  proxyScheme: undefined /* STRING */,
                  headers: headers /* JSON */,
                  ignoreSSLErrors: undefined /* BOOLEAN */,
                  useNTLM: undefined /* BOOLEAN */,
                  workstation: undefined /* STRING */,
                  useProxy: undefined /* BOOLEAN */,
                  withCookies: undefined /* BOOLEAN */,
                  proxyHost: undefined /* STRING */,
                  url: url /* STRING */,
                  timeout: undefined /* NUMBER */,
                  proxyPort: undefined /* INTEGER */,
                  password: undefined /* STRING */,
                  domain: undefined /* STRING */,
                  username: undefined /* STRING */

};




// result: JSON
var j = Resources["ContentLoaderFunctions"].GetJSON(params);

var result = j.records[0].attributes.url;

4. Give the service a name and test it. The output of this service is a url that can be appended to the instance_url that is returned in the response from the Authentication service.

Step 7: Modify a Record

Using the output from our last service, we can now easily modify the fields of the record ID that we just retrieved. Keep in mind, if you create a custom field and you want to modify its value, add a “__c” to the end of the field name (denotes custom field).

  1. Create a new service in your Thing
  2. Let’s give it a few “STRING” inputs: field, stringValue, and AccountName
  3. Input the following code:
var authJSON = me.AuthenticateSalesForce();

var token = authJSON.access_token;
var instance_url = authJSON.instance_url;

var stringJSON = '{"' + field + '":' + stringValue + "}";


var params = {
                  AccountName: AccountName /* STRING */
};

// result: STRING
var object_url = me.RetrieveSalesForceAccountRecordID(params);

var url = instance_url + object_url + "?_HttpMethod=PATCH";
var authString = "Bearer " + token;
var headers = {
   "authorization" : authString,
   "content-type" : "application/json"
};

var content = JSON.parse(stringJSON);

var params = {
                  proxyScheme: undefined /* STRING */,
                  headers: headers /* JSON */,
                  ignoreSSLErrors: undefined /* BOOLEAN */,
                  useNTLM: undefined /* BOOLEAN */,
                  workstation: undefined /* STRING */
                  useProxy: undefined /* BOOLEAN */,
                  withCookies: undefined /* BOOLEAN */,
                  proxyHost: undefined /* STRING */,
                  url: url /* STRING */,
                  content: content /* JSON */,
                  timeout: undefined /* NUMBER */,
                  proxyPort: undefined /* INTEGER */,
                  password: undefined /* STRING */,
                  domain: undefined /* STRING */,
                  username: undefined /* STRING */
};
// result: JSON
var result = Resources["ContentLoaderFunctions"].PostJSON(params);

 

A Note About Security

Salesforce has a few ways to authenticate your session.  The method described in this blog is the least secure way because ThingWorx has visibility to the username and password of the Salesforce account.  There are two other ways to authenticate and both use callback URLs.  Basically, a user sends a call to the login endpoint and enters user and password information directly into the Salesforce environment.  Salesforce then redirects to a callback URL that is appended with an authorization token.  If you’d like to implement one of the more secure methods, I would suggest using a REST endpoint to a ThingWorx service as your callback URL. More specifically, create a service that has a string input called “code.” Now, change your callback URL in your Salesforce connected app to something like https://login.salesforce.com/services/oauth2/authorize?response_type=code&client_id=&redirect_uri=>.  Now, when you navigate to the login link, it will send your authorization code to your ThingWorx service (this is because it appends “&code=” to the URL).  You’ll need to then send that code via the Content Loader Functions to receive your authorization token.  One thing to note is that the ThingWorx instance must be on HTTPS.  Salesforce does not allow HTTP callback URLs.  More information about Authentication can be found at https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_understanding_authentication.htm

If you have any questions about this blog or ThingWorx in general, don’t hesitate to leave a comment or contact EAC Product Development Solutions.

What if a bartender knew exactly when one of their kegs was about to tap out just by looking at a volume meter on an app on their phones? Their bar back could switch out the keg before impatient patrons demand more. What if liquor shelves had weight sensors that measured when someone adds or removes liquor? Or an app on a phone existed that notified management when and what liquor is moved? Or better yet, a storage system that communicates with the front bar, knows which liquor is being moved, and manages inventory according to actual usage? Inventory would be a lot more accurate and there would be less time spent trying to figure out what needs to be in the next order.

When smart connectivity allows for a smoother restaurant or brewery experience, you’re most likely going to have a better time without realizing it had anything to do with the Internet of Things (IoT). For businesses, IoT solutions are creating more opportunities to connect products with the Internet. And for the average consumer, IoT solutions are creating easier access and control of products through smartphones, tablets, and desktops.

Leaders are investing in an IoT strategy as they plan the future success of their products and services. You can add smart connectivity to your products – even if you’re in the beer industry.

Here are a few industry leaders that leverage the Internet of Things to drive their success.

Deschutes Brewery

Headquartered in Bend, Oregon, Deschutes Brewery has been making craft beer since 1988. You may be familiar with their rich porter Black Butte created with hints of chocolate and coffee or their Fresh Squeezed IPA brimming with grapefruit enriched hops.

The Deschutes team partnered up with a consultant group and Microsoft last year in efforts to improve their brewing process. With a total of nine brewing phases, each phase has to be closely watched to maintain the quality of their beer. Machine learning is the application of artificial intelligence that provides systems the ability to automatically learn and improve from experience without being programmed. Deschutes has implemented machine learning and predictive analysis to automate and improve their fermentation processes. When pairing IoT sensors with the Cortana Intelligence Suite, Microsoft’s predictive learning software, the analytics tool determines the percentage of beer fermented in each batch and predicts when it’s time to switch to the next phase. The Deschutes team can now accurately schedule the nine brewing phases accordingly to ensure the quality of beer is consistent with all of their batches.

Connecting the beer tank sensors with machine learning gave Deschutes an IoT solution and allowed them to improve their brew processes. Deschutes reduced their fermentation process by 24-48 hours. They are now able to focus more time on creating new brands and maintaining the quality of the existing ones. Deschutes is looking at furthering the use of this smart, connected technology by looking into using it for preventive maintenance for their equipment so that brewers would be alerted if parts are due for service or replacement.

Buffalo Wild Wings

Buffalo Wild Wings, headquartered in Minneapolis, MN, is a popular sports bar that has an average of 24-32 beers on tap. Due to major growth of the company and being one of the top 10 fastest-growing restaurants in the U.S., BWW needed to keep up with the growing demand of their customer’s needs. The company faced two major challenges. Both challenges prompted the need to leverage technology and the Internet of Things for an improved operational efficiency.

The first challenge was that they needed to eliminate the product loss that results from comping drinks, excessive or bad pours, and generous bartenders that give beer away without entering the sale in the system. BWW implemented a system called BeerBoard that monitors beer flow data from IoT sensors in the taps to Mulesoft, an Enterprise Service Bus (ESB), where managers can compare beer output to sales information pulled from their Aloha point-of-sale systems. Restaurant managers can accurately determine whether they are running an effective beer operation with the help of the IoT solution found from linking the sensors to BWWs data management systems.

Their second challenge was managing the demand of the assortment of beers for each location all year round. BWW used BeerBoard’s new SmartBar beer management platform to switch and assign new beers corresponding to tap lines. Pour data and sales data would be captured through the platform where all BWW restaurants would have access to the reports to measure performance of each beer. The ability to gain beer preference insight brought a powerful competitive advantage to Buffalo Wild Wing’s brand and reputation.

By working with a few different companies that provided the IoT flow sensors and a software solution to manage their data, BWW started to accurately predict preferences and optimize inventory planning. The company now leverages the Internet of Things to accurately track beer consumption.

How to Bring Your Products to Life with the IoT

Race up the learning curve and find a partner that’s driven to find and implement the right IoT solution for your unique business. Make sure they have the engineering expertise necessary to bring your products to life. EAC Product Development Solutions is a company that transforms the way companies design, manufacture, connect to, and service their products. EAC is on a mission to help companies innovate, optimize, and win in the marketplace by selecting the right IoT solution — like PTC ThingWorx. With ThingWorx allows organizations to connect their products to the Internet and give customers the tools they need for easy access and control.

Ready to dive in? Our team of specialists, engineers, and developers would love to help you bring a working proof of concept to life. The demo application image below is an example of how our engineers can use ThingWorx to pull together data from many sources and deliver data to your fingertips. The demo shows how a local brewery can use the app to access plant conditions, truck tracking, order tracking, weather forecasting, collaboration, and beer tasting — all in real-time simulation.

Watch our Connect Services video to see how our engineers can connect your products with the Internet of Things!


Knowledge is power. Keep track of your data if you’re not doing it already. You’re bound to learn something from it. Better yet – apply smart connectivity to your process. Contact our Design and Engineering Services at EAC Product Development Solutions to realize your product potential and to find your IoT solution.

In my last blog, Hearing Voices Through Connected Manufacturing & Machine Learning I tried to convey how expensive manufacturing equipment could (and should) be telling you how it’s performing and if it’s going to malfunction. While it seems futuristic and expensive, I’ll attempt to dispel both challenges in this post.

One starting point is the reality of the Internet of Things (IoT) and its impact on manufacturing is recognized by major governments across the globe. It’s referred to as ‘Smart Nation’ in Singapore, ‘Made in China 2025’ in China, ‘Industries 4.0’ in Germany, and generally as the Industrial Internet of Things (IIoT) by various industry leading organizations in the United States.

Regardless of what the governing bodies are doing, we’re in business to make money.

How can you do that?

Use the IIoT and all that it can do to achieve your business initiatives.

That’s when some new compelling or wiz-bang approach to things can actually make sense (or cents). What I mean is this, don’t treat the IIoT as something new or as a separate initiative. Rather, embrace the technology for what it is and how it can propel your existing business initiatives.

The ideals of my previous blog, preventive maintenance, enterprise monitoring, and increased ROI are probably already on your visions and strategy hit-list for making more money. These are exactly the core business initiatives that are possible. When these are being met, the feeling of work being ‘expensive’ shifts to understanding the value of smart, connected operations. This comes from connected systems and equipment flowing data from previously disparate systems into a data refinery directly connecting operational metrics to core business initiatives in real-time. Then you can focus on the value.

Move forward into what’s current and available if you’ve been sitting for a while.

As for this being ‘futuristic,’ well I guess you could say it is, but it’s more focused on moving forward. This is fundamentally about transforming the way you design, manufacture, connect to, and service your products. It’s a major shift into the future.

It’s not about unobtainable science-fiction — rather its attainable with modern equipment and easy add-ons to old equipment. This is enabled even further through easy access to high volume scalable process computer systems in the cloud and at the edge. It’s even become expected in newer equipment.

The advent of IoT Platforms like PTC’s ThingWorx has created systems that address all aspects of the IoT stack and support smooth and complete implementation. Starting with Industrial Connectivity to accelerate the connection of existing equipment into a central hub, you can rapidly bring equipment into the ‘connected’ state by feeding the ability to give your equipment a voice. A scalable and flexible environment for creating applications and role-centric mashups of refined information comes together in ThingWorx Foundation. Augmented Reality runs right through this system as well as predictive analytics in ThingWorx Analytics. ThingWorx Analytics are available to turn these concepts into reality and truly give the equipment in your operation a voice.

So, are you hearing voices yet? Or maybe wishing that you did? We’d love to help make this happen — whether it is through connecting the dots related to strategy, providing technology, implementing it, or even helping to retro-fit existing equipment so it can speak, let us hear your voice and we’ll help give your operation a voice as well.

If you’d like more information about connecting your products through smart manufacturing, you may find our brochure helpful.

EAC Connect Services - Download Brochure

Are you hearing voices? If not, you should be!

Well, are you hearing voices? You know, the voices telling you how to make more money, or the whispers of how you can improve your business, or maybe they’re loud and proud notices of problems before they occur. Where would such messages of insight and prosperity come from? I’m talking about the voices of all that expensive equipment you have that keeps producing your product.

As manufacturers, we all invest heavily in the equipment, maintenance, and staff to keep it running smoothly or sometimes get it running quickly after unexpected malfunctions. What would it mean to your business if your equipment could tell you how well it’s running and if something is going to malfunction before it even happens? The ability for your equipment to ‘talk’ to you could substantially impact planning, proactive maintenance, utilization, production rates, overall equipment effectiveness (OEE), and most certainly the bottom line.

Business 101: businesses require a solid Return on Investment (ROI). High cap ex-equipment implies the “I” and requires production to make the “R.” We all run this daily balance of scheduling maintenance, guessing what needs to be fixed, hoping everything runs right over the third shift and talking ourselves into the thought that we’re getting the most from the equipment. Taking a long look in the mirror might challenge that thought.

Considering connectivity is cheaper and ‘nearly’ everywhere, along with easier ways to stream, collect and refine data into actionable information, the realistic impact of the Industrial Internet of Things (IIoT) brings some futuristic opportunities to your desktop for implementation today.

Think About the Possibilities

What if your equipment could self-diagnose problems, predict failure timelines and prioritize maintenance based on enterprise-wide visibility to OEE, production demands and current performance?

How about leveraging Augmented Reality (AR) to peer into the heart of operating equipment for live feedback and real-time vision-based maintenance instruction holo-deck style?

What if you could view the rates and predicted issues of entire production lines from a single-pane-of-glass? Imagine viewing this with live interactive graphics, drill-down analytics, and mashups pulling data from existing silos of information.

While some of this seems like a ‘nice-to-have future state,’ rest assured, this is as real and available as it comes. It’s what can be implemented so you can start hearing voices. It’s ThingWorx. ThingWorx is a tool to enable developers such as yourself to rapidly connect, create, and deploy breakthrough applications, solutions, and experiences for the smart, connected world. Furthermore, ThingWorx Analytics enables you to uncover the true value of your smart connected manufacturing floor data. Learn from past data, understand and predict the future, and make decisions that will enhance outcomes.

If you’d like more information about connecting your products through smart manufacturing, explore our piece that serves as a primer on the fundamentals of ThingWorx.

While I’d like to think I’m a good storyteller and an artist, I’m pretty sure I’m not ‘awesome’ at either. That’s one more reason to pay attention to Augmented Reality (AR) these days.

As an engineer and a designer, I frequently find myself trying to explain a widget, a feature, or a design to someone. Often this takes lots of hand-waving, white-board markers, and innumerable sketches. This got better over time with improved drawing skills and communication techniques. It was even better still when I could put a physical model in someone’s hands by using a 3D printer for rapid prototyping. Well, things just got a lot more interesting when we started using AR through ThingWorx Studio to do virtual prototyping.

While I spend most of my time designing business strategies for the IoT and connecting products using ThingWorx as an IoT platform, the AR portion of ThingWorx is simply fun to use. One great way to employ the tool is to super-impose streaming data and information directly onto the product while looking through a mobile device. AR Prototyping, on the other hand, is the ability to superimpose alternate designs into the real world through a mobile device such that you can experience a design as it was intended. The kicker is that you can whip together a couple dozen designs, review them virtually — in person or remotely — and have a fabulous understanding of the design in less time than it takes to print even one prototype.

In the video below we’re playing with the app ThingWorx View by PTC. Watch this model of a motorcycle come to life with Augmented Reality (AR). We’ve used this technology for virtual prototyping. For some of our customers we are able to swap in and out CAD models to virtually prototype new designs and configurations.

So, if you’re like me and you want to convey a design idea in a hurry — even faster than a rapid prototype — you should really look into AR Prototyping. This has sliced-bread beat no problem.

If you want to start virtual prototyping, ask us how here! We’d love to help you transform the way you design and connect to your products.

I applaud anyone currently considering how the Internet of Things (IoT) can transform their company and their approach to competition. This is what every industrial and consumer product company should be doing right now. While helping companies through the early stages of developing IoT strategies we’ve recognized a common challenge. Teams can get lost in the excitement of enabling their first “thing” and lose focus on their long-term vision and the value they can extract from streaming data. We get it! The IoT is exciting. That is why we always coach our clients to select an IoT platform (software) that allows them to quickly and easily develop applications that present valuable, digestible information to employees and customers – whether or not a role or data stream was part of the initial strategy.
This week provided me with a front row seat to unexpected value from streaming data. While working on an IoT proof of concept for a client, my team was able to refine a data stream and deliver a new application to an audience that was not part of the initial scope of the project. The only reason we were able to create this new application without charging an additional fee is because we selected ThingWorx, a solution by PTC as the application/mashup development tool. Thingworx helps teams create new applications in minutes.

I try to spend the majority of my time working on IoT strategies and how they can transform companies and competition. My background in engineering and software development provides me with a unique view into the time spent making things smart — providing sensor networks, communication layers, and ultimately enabling heretofore unseen analytics in real-time on remote products. The project the Connect Services team and I were working on this week involved developing mashups, which stemmed from earlier strategy work and team alignment. Mashups are the collection and presentation of data from smart things and systems enabling real-time business awareness and decision-making. For this project, we had already developed storyboards for the apps that would enable core product and service differentiation. Everyone was on board and excited.

Once the proof of concept device was wired and streaming data, we saw a whole new role that would benefit from the data that was streaming. Previously, the engineers would have been left hanging and the data would have been left alone and isolated. This is because developing an extra application for ancillary roles would have taken the project well off track. Leveraging ThingWorx as our application development environment, we were able to build a concept from scratch in literally seconds. What’s really cool is that it didn’t take any code at all either, just drag, drop, save, and we were in business. The concept made sense and in literally a couple of hours (not days or weeks) we had created an entirely new app and use case for the data. We were able to refine the data in real-time and create a whole new monitoring experience. Again, this was done without coding, just simply drag and drop.

So, here’s my recommendation — make sure your IoT platform supports your IoT strategy. And what’s more, be sure the platform you select is a tool that is flexible, fast, and fun — like ThingWorx. You will likely find more and more ways to consume, refine, and benefit from the data your connected products and enterprise produce just because it’s easy to do. And this, after all, is what your IoT platform should do — it should enable your existing business initiatives and accelerate your business initiatives.

EAC Connect Services is here to help you develop your IoT strategy, build and connect your proof of concept, and select the appropriate platform. Let us be your partner in the ever-changing world of the IoT. Please let us know if we can help you transform your business and help you beat your competition.