Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

REST API POST: change device name and other properties


andrea.zanantoni@gmail.com

Question

Hi,

I'm trying to test the REST API via PHP.

GET is ok, I'm able to read and display each data in my application.

Now I want to test the POST and PUT API.

I tryed to change a device name, but nothing happens.

 

This is my code:

$dati = '{"id":197,"name":"zanna","roomID":6,"type":"com.fibaro.motionSensor","baseType":"com.fibaro.lifeDangerSensor","enabled":true,"visible":true,"isPlugin":false,"parentId":195,"remoteGatewayId":0,"interfaces":["fibaroAlarm","fibaroAlarmArm","fibaroBreach","tamper","zwave","zwaveSceneActivation"],"properties":{"parameters":[{"id":1,"lastReportedValue":0,"lastSetValue":0,"size":2,"value":0},{"id":2,"lastReportedValue":0,"lastSetValue":0,"size":2,"value":0},{"id":3,"lastReportedValue":0,"lastSetValue":0,"size":1,"value":0},{"id":4,"lastReportedValue":0,"lastSetValue":0,"size":1,"value":0},{"id":5,"lastReportedValue":255,"lastSetValue":255,"size":1,"value":255},{"id":6,"lastReportedValue":255,"lastSetValue":255,"size":1,"value":255},{"id":7,"lastReportedValue":255,"lastSetValue":255,"size":1,"value":255},{"id":8,"lastReportedValue":255,"lastSetValue":255,"size":1,"value":255},{"id":9,"lastReportedValue":0,"lastSetValue":0,"size":1,"value":0},{"id":10,"lastReportedValue":20,"lastSetValue":20,"size":1,"value":20},{"id":11,"lastReportedValue":200,"lastSetValue":200,"size":1,"value":200},{"id":12,"lastReportedValue":8,"lastSetValue":8,"size":1,"value":8},{"id":13,"lastReportedValue":0,"lastSetValue":0,"size":1,"value":0},{"id":14,"lastReportedValue":0,"lastSetValue":0,"size":1,"value":0}],"zwaveCompany":"Fibargroup","zwaveInfo":"3,3,52","zwaveVersion":"2.1","pollingTimeSec":0,"alarmDelay":"0","alarmExclude":"false","alarmTimeTimestamp":"0","armConditions":"{}","armConfig":"0","armDelay":"0","armError":"{}","armTimeTimestamp":"0","armed":"false","configured":"true","dead":"false","deviceControlType":"0","deviceIcon":"21","emailNotificationID":"0","emailNotificationType":"0","endPointId":"1","fibaroAlarm":"false","lastBreached":"1479350609","liliOffCommand":"","liliOnCommand":"","log":"","logTemp":"","manufacturer":"","markAsDead":"true","model":"","nodeId":"38","parametersTemplate":"85","productInfo":"1,15,5,1,16,2,2,1","pushNotificationID":"0","pushNotificationType":"0","remoteGatewayId":"0","saveLogs":"true","sceneActivation":"0","serialNumber":"","smsNotificationID":"0","smsNotificationType":"0","tamper":"false","useTemplate":"true","userDescription":"","value":"false"},"actions":{"forceArm":0,"meetArmConditions":0,"reconfigure":0,"sceneActivationSet":0,"setArmed":1},"created":1478196735,"modified":1478196735,"sortOrder":112}';
$stringa_dati = json_encode($dati);

// Get cURL resource
$curl = curl_init();

// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_CUSTOMREQUEST => 'PUT',
    CURLOPT_POSTFIELDS => $stringa_dati,
    CURLOPT_HTTPHEADER => array('Content-Type: application/json','Content-Length: ' . strlen($stringa_dati)),
    CURLOPT_URL => $ZanGeneric->domotica_hc2_api . '/devices/197',
    CURLOPT_TIMEOUT => 5,
    CURLOPT_USERAGENT => 'Codular Sample cURL Request'
));

// Send the request & save response to $resp
$resp = curl_exec($curl);

//Trasformo la stringa in un oggetto JSON
$obj = json_decode($resp,true);

// Close request to clear up some resources
curl_close($curl);

 

Is there someone can send an example?

Thanks

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...