• 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

  • Hybrid Multi-Cloud Environments Are Becoming UbiquitousJuly 12, 2023
  • Data Protection on the InternetJuly 12, 2023
  • Basics of BJT TransistorJuly 11, 2023
  • What is Confidential Computing?July 11, 2023
  • How a MOSFET WorksJuly 10, 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