diff --git a/cmd/appengine/device.go b/cmd/appengine/device.go index cbbf835..6dbeecb 100644 --- a/cmd/appengine/device.go +++ b/cmd/appengine/device.go @@ -1079,14 +1079,25 @@ func devicesSendDataF(command *cobra.Command, args []string) error { } var parsedPayloadData interface{} + + fmt.Println(payloadData) + if err := payloadType.IsValid(); err == nil { - if parsedPayloadData, err = parseSendDataPayload(payloadData, payloadType); err != nil { + + if payloadData == "nil" { + parsedPayloadData = nil + }else{ + if parsedPayloadData, err = parseSendDataPayload(payloadData, payloadType); err != nil { return err } + } + + } else { // We have to treat it as an aggregate. aggrPayload := map[string]interface{}{} if err := json.Unmarshal([]byte(payloadData), &aggrPayload); err != nil { + fmt.Println("A") return err } @@ -1099,6 +1110,7 @@ func devicesSendDataF(command *cobra.Command, args []string) error { fullPath := fmt.Sprintf("%s/%s", interfacePath, k) mapping, err := interfaces.InterfaceMappingFromPath(iface, fullPath) if err != nil { + fmt.Println("B") return err } @@ -1148,8 +1160,16 @@ func devicesSendDataF(command *cobra.Command, args []string) error { var sendDataCall client.AstarteRequest if !skipRealmManagementChecks { - // We can delegate the entirety of this to astarte-go - sendDataCall, err = astarteAPIClient.SendData(realm, deviceID, deviceIdentifierType, iface, interfacePath, parsedPayloadData) + + if parsedPayloadData==nil { + // We can delegate the entirety of this to astarte-go + sendDataCall, err = astarteAPIClient.UnsetProperty(realm, deviceID, deviceIdentifierType, interfaceName, interfacePath) + }else{ + // We can delegate the entirety of this to astarte-go + sendDataCall, err = astarteAPIClient.SendData(realm, deviceID, deviceIdentifierType, iface, interfacePath, parsedPayloadData) + } + + } else { // Don't risk it. Use raw functions and trust the server to fail, in case. switch interfaceTypeString {