I am trying to make a CoAP NON server using CoAPSharp binary in Visual Studio 2015. My target device is Raspberry Pi with Windows IoT core.
"Remotesender" part has the error. I don't know how to solve it
/// <summary>
/// Called when a request is received
/// </summary>
/// <param name="coapReq">The CoAPRequest object</param>
void OnCoAPRequestReceived(CoAPRequest coapReq)
{
//This sample only works on NON requests of type GET
//This sample simualtes a temperature sensor at the path "sensors/temp"
string reqURIPath = (coapReq.GetPath() != null) ? coapReq.GetPath ().ToLower() : "";
/**
* Draft 18 of the specification, section 5.2.3 states, that if against a NON message,
* a response is required, then it must be sent as a NON message
*/
if (coapReq.MessageType.Value != CoAPMessageType.NON)
{
//only NON combination supported..we do not understand this send a RST back
CoAPResponse msgTypeNotSupported = new CoAPResponse (CoAPMessageType.RST, /*Message type*/
CoAPMessageCode.NOT_IMPLEMENTED, /*Not implemented*/
coapReq.ID.Value /*copy message Id*/);
msgTypeNotSupported.Token = coapReq.Token; //Always match the request/response token
msgTypeNotSupported.RemoteSender = coapReq.RemoteSender;
//send response to client
this._coapServer.Send(msgTypeNotSupported);
}
else if (coapReq.Code.Value != CoAPMessageCode.GET)
{
//only GET method supported..we do not understand this send a RST back
CoAPResponse unsupportedCType = new CoAPResponse (CoAPMessageType.RST, /*Message type*/
CoAPMessageCode.METHOD_NOT_ALLOWED, /*Method not allowed*/
coapReq.ID.Value /*copy message Id*/);
unsupportedCType.Token = coapReq.Token; //Always match the request/response token
unsupportedCType.RemoteSender = coapReq.RemoteSender;
//send response to client
this._coapServer.Send(unsupportedCType);
}
else if (reqURIPath != "sensors/temp")
{
//classic 404 not found..we do not understand this send a RST back
CoAPResponse unsupportedPath = new CoAPResponse (CoAPMessageType.RST, /*Message type*/
CoAPMessageCode.NOT_FOUND, /*Not found*/
coapReq.ID.Value /*copy message Id*/);
unsupportedPath.Token = coapReq.Token; //Always match the request/response token
unsupportedPath.RemoteSender = coapReq.RemoteSender;
//send response to client
this._coapServer.Send(unsupportedPath);
}
else
{
//All is well...send the measured temperature back
//Again, this is a NON message...we will send this message as a JSON
//string
Hashtable valuesForJSON = new Hashtable();
valuesForJSON.Add("temp", this.GetRoomTemperature());
string tempAsJSON = JSONResult.ToJSON(valuesForJSON);
//Now prepare the object
CoAPResponse measuredTemp = new CoAPResponse(CoAPMessageType.NON, /*Message type*/
CoAPMessageCode.CONTENT, /*Carries content*/
coapReq.ID.Value/*copy message Id*/);
measuredTemp.Token = coapReq.Token; //Always match the request/response token
//Add the payload
measuredTemp.Payload = new CoAPPayload(tempAsJSON);
//Indicate the content-type of the payload
measuredTemp.AddOption(CoAPHeaderOption.CONTENT_FORMAT,
AbstractByteUtils.GetBytes(CoAPContentFormatOption.APPLICATION_JSON));
//Add remote sender address details
measuredTemp.RemoteSender = coapReq.RemoteSender;
//send response to client
this._coapServer.Send(measuredTemp);
}
}
Error:
error: CS1061 C# does not contain a definition for and no extension method accepting a first argument of type could be found (are you missing a using directive or an assembly reference?)
Simply following the tutorial on CoAPSharp official website.