recent update broke script

Hi,

I was running a script on my CAPsMAN to report device presence to an external REST service.
At some point end of January this stopped working unnoticed. Since I didn’t change anything with my script at this point in time I can only guess that some upgrade in the 6.43 line broke it.

The script does only limited things:

  • it checks caps-man registrations for certain MAC addresses
  • it reports via /tool fetch to the REST service
  • and it uses a global persistent variable to reduce the reports to changes only

I’m not exactly sure what stopped working exactly but previously I had files in the base directory after the /tool fetch execution which do not appear anymore.
I’m struggling to find the reason or exact detail what is failing.

The script looks roughly like this:

:global WolfgangON

{
  :local exists [/caps-man reg find mac-address="MAC"];
  :if ($exists!="") do={
     :if ($WolfgangON != 1) do={
        /tool fetch url="http://192.168.250.12:8080/rest/items/SensorPhoneWolfgang" http-content-type="text/plain" http-data="ON" ascii=yes http-method=post;
       :set WolfgangON 1
     }
  }  else={
     :if ($WolfgangON != 0) do={
        /tool fetch url="http://192.168.250.12:8080/rest/items/SensorPhoneWolfgang" http-content-type="text/plain" http-data="OFF" ascii=yes http-method=post; 
        :set WolfgangON 0
     }
  }
}

Any hints? As said this was working for some time before it suddenly stopped.
Currently I’m on version 6.44


Thanks,
Wolfgang

Hi,

Check the fetch command. From v6.44 they removed the “http-content-type” option.

You must now use the option http-header-field=“Content-Type: xxx”.


Andrej

:global WolfgangON
{
  :local state
  :local exists [/caps-man reg find mac-address="MAC"];
  :if ($exists!="") do={
     :if ($WolfgangON != 1) do={
       :set state "ON"
       :set WolfgangON 1
     }
  }  else={
     :if ($WolfgangON != 0) do={
	:set state "OFF"
        :set WolfgangON 0
     }	 
     /tool fetch url="http://192.168.250.12:8080/rest/items/SensorPhoneWolfgang" http-content-type="text/plain" http-data=$state ascii=yes http-method=post; 	 
  }
}

Hi,
Save “OFF” or “ON” with $state
This will make it look simpler.you can try it. :slight_smile:

Thanks, didn’t notice this and it helped.
One addition/clarification though:
http-header-field=“Content-Type: text/plain” did not work, but
http-header-field=“content-type:text/plain” works

I guess it’s the whitespace and not the upper case but I haven’t checked.