IHC Soap client for esp8266

This is a library to make soap requests to the IHC controller from an esp8266. I am using this library in my DingSwitch project. It implements a limited set of the soap requests: authentication, get and set runtime values and notification.

Download

The library is included in the arduino library manager, so you can install it directly from the arduino IDE.

The library can also be downloaded here from github:

https://github.com/dingusdk/esp8266IHCSoapClient

How does it work

The soap functionally to has been hard coded into regular http requests – no fancy soap library to do the stuff. This is because of the limited memory of the esp8266. The parsing of the soap xml response is also very primitive, but it work. The library implements:

  • Authentication
  • Get runtime values (bool, integer and float)
  • Set runtime values (bool, integer and float)
  • Notification of resource changes

See the examples folder. To make the examples work you should modify the settings.h file with you wifi and ihc settings.

The tricky part here is the notification, because this should be done with the “waitForResourceValueChanges” soap function using long polling. To make this possible the HTTPClient has been modified to make a request where it does not wait for the response.

A callback function is registered with the IHCSoapClient.WaitForResourceValueChanges function, and you enable notification for a resource id using the IHCSoapClient.EnableRuntimeValueNotifications function. You may call the EnableRuntimeValueNotifications multiple time if you want to be notified for more then one resource.

Within the loop function you must call HandleLoop. See the “notify” example.

void loop() {
  if ( ! IHCSoapClient.HandleLoop()) {
    // Redo ihc setup in 30 sec
    // Authenticate, 
    // EnableRuntimeValueNotifications
    // WaitForResourceValueChanges
  }
}

For testing you can ignore the return value of HandleLoop, but if you want to make something that is more stable (handling when the ihc session is lost), you should check the return value of HandleLoop and when false you should wait some time (I use 30 sec), and the reinitialize the ihc setup.

Note: Currently only boolean resources are supported for notification.

The library also have a function to get the project file from the IHC controller, but since the project file is usually too big to be handled in the limited memory available of an esp8266, it should be done client side in the browser. The GetProject will stream the response directly to a WifiClient. I will not go more into details how that is done – this could be a separate post of it own.

IHC Resources ids

You can find ihc resource ids by looking in the IHC project file – it is a XML file.
An easier way is to use my IHC Alternative Service View application

In this application you can see a tree view of you your installation, expand and click the resource and get the id.

 

2 responses to “IHC Soap client for esp8266”

  1. Arslan Munir says:

    Hello
    I have been using this library and it is awesome but i’ve encountered a problem that it not deleting the previous recieved and hence the free heap gets lower and lower on memory untill te system crashes. can you tell me how can i resolve this problem?

    • Jens says:

      There is a leak when the GetRuntimeValueXXX functions are failing (When the controller responds anything else than status code 200).
      I have fixed this leak and updated the library

Leave a Reply

Your email address will not be published. Required fields are marked *