edgexfoundry / device-sdk-go

Owner: Device WG

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

code: 503 , message: failed to send a http request

Vincent990413 opened this issue · comments

Hi,I've already added the device-simple and profile file.

and when I try to call the cmds inside, it shows code 503,message: failed to send a http request.

Here is the result.

message: failed to send a http request

and here is my code from simpledriver.go

package driver

import (
"bytes"
"fmt"
"image"
)

var messageValue string = "Hello EdgeXFoundry!"

......

// HandleReadCommands triggers a protocol Read operation for the specified device.
func (s *SimpleDriver) HandleReadCommands(deviceName string, protocols map[string]models.ProtocolProperties, reqs []sdkModels.CommandRequest) (res []*sdkModels.CommandValue, err error) {
s.lc.Debugf("SimpleDriver.HandleReadCommands: protocols: %v resource: %v attributes: %v", protocols, reqs[0].DeviceResourceName, reqs[0].Attributes)

res = make([]*sdkModels.CommandValue, len(reqs))
for i, req := range reqs {
	if reqs[i].DeviceResourceName == "getMessage" {
			cmdResp, _:=sdkModels.NewCommandValue(req.DeviceResourceName, common.ValueTypeString, messageValue)
			res[i] = cmdResp
	}
}

return

}

// HandleWriteCommands passes a slice of CommandRequest struct each representing
// a ResourceOperation for a specific device resource.
// Since the commands are actuation commands, params provide parameters for the individual
// command.
func (s *SimpleDriver) HandleWriteCommands(deviceName string, protocols map[string]models.ProtocolProperties, reqs []sdkModels.CommandRequest,
params []*sdkModels.CommandValue) error {
// var err error

for i,r := range reqs {
	switch r.DeviceResourceName {
	case "setMessage":
		messageValue = params[i].ValueToString()
	}
}

return nil

}

func (s *SimpleDriver) ValidateDevice(device models.Device) error {

return nil

}

Please tell me what I should do to fix this, thanks a lot !!!!! Heart~