• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » URL Format For Sending Commands Over HTTP (cURL) to IBM Watson IoT

By Abhishek Ghosh September 11, 2019 7:19 am Updated on September 11, 2019

URL Format For Sending Commands Over HTTP (cURL) to IBM Watson IoT

Advertisement

HTTP commands open up wider way to control. This is the corrosponding GitHub repository with a basic example matched with this guide. Already we have shown the serious usages of the method through our Controlling AC Powered Appliances With ESP32 guide. Here is a Discussion on URL Format or Sending Commands Over HTTP (cURL) to IBM Watson IoT.

IBM’s platform is configured to accept events from the device and commands from an application i.e. the cURL command over HTTP. We need different headers for authentication. The devices authenticate with user-token-auth and the device’s token. But the applications authenticate with API keys. Here is documentation on IBM’s website.

Look at the code on GitHub. Notice the below lines :

Advertisement

---

Vim
1
2
3
4
5
…
#define CMD_STATE "/gpio/"
 
const char commandTopic[] = "iot-2/cmd/+/fmt/+";
…

URL Format or Sending Commands Over HTTP cURL to IBM Watson IoT

When we run this command the LED becomes ON :

Vim
1
curl -u <use-the-API-Key>:<use-auth-token> -H "Content-Type: text/plain" -v -X POST http://<your org>.messaging.internetofthings.ibmcloud.com:1883/api/v0002/application/types/<yourDeviceType>/devices/<yourDeviceId>/commands/gpio -d "on"

When we run this command the LED becomes OFF :

Vim
1
curl -u <use-the-API-Key>:<use-auth-token> -H "Content-Type: text/plain" -v -X POST http://<your org>.messaging.internetofthings.ibmcloud.com:1883/api/v0002/application/types/<yourDeviceType>/devices/<yourDeviceId>/commands/gpio -d "off"

Our command URL is this :

Vim
1
http://<your org>.messaging.internetofthings.ibmcloud.com:1883/api/v0002/application/types/<yourDeviceType>/devices/<yourDeviceId>/commands/gpio

We can not alter this format much as that will not match IBM’s server configuration. You can change the phrase gpio to something like led to test – that will work when you change the #define CMD_STATE "/gpio/" line to #define CMD_STATE "/led/". IBM’s configuration supports nomenclature such as gpio1, led1 and so on. That is a helpful trick to add multiple things.

The second part you need to know is about this line :

Vim
1
const char commandTopic[] = "iot-2/cmd/+/fmt/+";

I used + as a wildcard in two places – the + between /cmd/ and /fmt/ could be changed to gpio for the above example code.

You can change it the code to something like the below :

Vim
1
2
const char commandTopic1[] = "iot-2/cmd/led/fmt/+";
const char commandTopic2[] = "iot-2/cmd/led1/fmt/+";

So, in your code if you decide to change the end of the command to fool, you should change two lines on code :

Vim
1
2
3
#define CMD_STATE "/fool/"
 
const char commandTopic[] = "iot-2/cmd/fool/fmt/+";

The command to make it working will be :

Vim
1
http://<your org>.messaging.internetofthings.ibmcloud.com:1883/api/v0002/application/types/<yourDeviceType>/devices/<yourDeviceId>/commands/fool

So, you are changing 3 things to rename a thing :

1. The #define CMD_STATE line
2. The const char commandTopic[] line
3. End of the URL to send cURL command i.e. ../devices//commands/gpio

We already know that we can use an Android app to create button and send the cURL requests to switch on and switch off the LED.

This ends this guide. Our next chapters will be connecting it to Node-RED to create a web toggle button.

Tagged With how to send a curl command to an iot device
Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to URL Format For Sending Commands Over HTTP (cURL) to IBM Watson IoT

  • WROOM ESP32 Example Codes For IBM Watson IoT Platform

    Here Are Few WROOM ESP32 Example Codes For IBM Watson IoT Platform So That Anyone Can Get Started With Both of Them Without Huge Experience.

  • How to Control Multiple Relays With Single Arduino ESP32?

    Before How to Control Multiple Relays With Single Arduino ESP32 Testing, You Need to Learn How to Create Multiple MQTT Channels & Fetch Data.

  • Sending Commands to IBM Watson IoT to Trigger Event on Device

    Our basic need can be controlling a LED connected with remote device. Here is How to Send Commands to IBM Watson IoT to Trigger Event on Device.

  • Control ESP32 Arduino LED from IBM Watson IoT

    Here is How to Turn On and Off an LED Connected With ESP32 Arduino From IBM Watson IoT Using Simple Bash Scripts. You Can Use Relay Instead of LED.

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Apple Vision Pro : Basic DetailsJune 9, 2023
  • What is Rapid Application Development (RAD)June 9, 2023
  • How to Install Appwrite as a Backend ServerJune 8, 2023
  • What is Application Lifecycle ManagementJune 8, 2023
  • How to Add Auto Anchor to WordPress HeadingsJune 7, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT