Topics

Iotivity Client


elizabethnathaniaw93@...
 

Hi,
I'm Elizabeth.
I've tried to implement Iotivity on Raspberry Pi 3 Model B + Enviro Phat. And I used OTGC for Linux as Iotivity Client.
Now, I want to build my own customize Iotivity client + interfaces. Is there any references to do that?
Thanks.


김정진
 

Hi.

You can see the sample client app below apps directory. https://github.com/openconnectivity/IOTivity-Lite-setup /apps

Good luck.

2020년 1월 2일 (목) 오후 8:24, <elizabethnathaniaw93@...>님이 작성:

Hi,
I'm Elizabeth.
I've tried to implement Iotivity on Raspberry Pi 3 Model B + Enviro Phat. And I used OTGC for Linux as Iotivity Client.
Now, I want to build my own customize Iotivity client + interfaces. Is there any references to do that?
Thanks.



--

김정진 책임연구원 (Jeongjin Kim) Mobile. 010-4223-8152  j.jin@vinetech.com

㈜바인테크 Vinetech Co., Ltd. | IoT Platform Lab | New Technology BU (신기술사업부)

Dir Tel: 82-2-2182-8392  | Tel: 82-2-2182-8300 | Fax: 82-2-2182-8399

(05836) 서울시 송파구 법원로11길 7, C동 1207호 (문정동, 현대지식산업센터)

#1207~1210, 7, Beobwon-ro 11-gil, Songpa-gu, Seoul, 05836, Rep. of KOREA

 


Clarke Stevens
 

Elizabeth,

This presentation may help. In order to implement any arbitrary IoT device you only need to create the appropriate input file with OCF resources. You can see a few examples that work with Raspberry Pi and various Pi Hat boards under the Sample-Rapberry-Pi-Code directory. This presentation explains a little more about any arbitrary IoT device. If you are using a different OS or a microcontroller, you will need to compile for that platform, but essentially the same source code should work. I think you already built for a Due microcontroller, so you can see what the differences are there.

In either case, just create the input file and run DeviceBuilder then compile the code for the target platform.

Hopefully, that helps.

Thanks,
-Clarke



On Jan 2, 2020, at 4:24 AM, elizabethnathaniaw93@... wrote:

Hi,
I'm Elizabeth.
I've tried to implement Iotivity on Raspberry Pi 3 Model B + Enviro Phat. And I used OTGC for Linux as Iotivity Client.
Now, I want to build my own customize Iotivity client + interfaces. Is there any references to do that?
Thanks.


elizabethnathaniaw93@...
 

Thanks, Jeongjin and Clarke!
I've tried that example before. I'm wondering is it possible to customize OTGC? Because I try to create my user interface.


Clarke Stevens
 

Elizabeth,

Yes. That is why it was created. All the source code is available (I’ll have to look up the reference for you, but I think it is under the developer section on the OCF web site). You can take the source code and add any features you want for your particular use, knowing that it already works and passes certification with all security features, onboarding, etc.

OTGC is available in Linux and Android that is up to date. This year, I plan to make OTGC into a real open source project and plan to bring in the iOS and Windows versions (that are currently unmaintained). Hopefully, we will get volunteers to bring those versions up to date.

Thanks,
-Clarke

On Jan 6, 2020, at 5:57 PM, elizabethnathaniaw93@... wrote:

Thanks, Jeongjin and Clarke!
I've tried that example before. I'm wondering is it possible to customize OTGC? Because I try to create my user interface.


elizabethnathaniaw93@...
 

Hi Clarke,
Thanks. I've downloaded the OTGC Linux.
Also, is there any example in C for the client?
In iotivity-lite source in github, there are several examples of the client in C, but I couldn't found an example when it runs get or post function (e.g. turn on/off the light, get light state) from the client that is written in C file.


George Nash
 

Are you looking for example code of a client or a server?

 

If you are looking for a sample server the smart_home_server_linux sample is the most up to date and complete sample for the server. Unfortunately we don’t have a client sample to interact with this server it is typically exercised by the certification and testing tool (CTT).

 

If you are looking for sample clients I would suggest checking out the temp_sensor_client_linux

 

 

The simpleclient will talk to the simpleserver sample.  However these samples are not using standardized resources for that reason I typically don’t recommend them as a samples but they are some of the few samples that we have both a client and server that talk with each other.

 

Hope this helps.

 

George

 

From: iotivity-dev@iotivity.groups.io <iotivity-dev@iotivity.groups.io> On Behalf Of elizabethnathaniaw93@...
Sent: Wednesday, February 19, 2020 8:29 AM
To: iotivity-dev@iotivity.groups.io
Subject: Re: [dev] Iotivity Client

 

Hi Clarke,
Thanks. I've downloaded the OTGC Linux.
Also, is there any example in C for the client?
In iotivity-lite source in github, there are several examples of the client in C, but I couldn't found an example when it runs get or post function (e.g. turn on/off the light, get light state) from the client that is written in C file.


Clarke Stevens
 

George,

I think she’s looking to build a server. Besides the example George mentions that is distributed in the IoTivity-lite repo, There are many samples available. There are several for Raspberry Pi with various Pimoroni cards. There are Linux examples for a dimmable light using GTK to implement a GUI. I also just put one up to implement (unfortunately without any GUI). I’ve listed the repos below and included a deck that shows how to build them from a JSON input file. You can use DeviceBuilder to automatically build a working C file in about 30 seconds. I’m working on updating all the documentation, but I’m not through yet.

Also, as George knows, the OTGC you downloaded is an excellent and up-to-date client. It sounds like you may already have that working.  So here are a bunch of links you can try.


For the following examples, you will the the ProjectScripts in this repo:


There is a bug, so you may need to run it twice. I’ve tried for a long time to debug this, but so far unsuccessfully. Then, you need to follow the instructions in this PowerPoint:


Here are the examples:

Also, you may have found these already, but these are the two up-to-date versions of the OTGC client. These are in IoTivity-lite (i.e. C):

I apologize if any of this is not accurate. I’m hoping to have it all cleaned up by mid March, but I’m happy to help you if you get stuck.

Thanks,
-Clarke



On Feb 19, 2020, at 1:17 PM, George Nash <george.nash@...> wrote:

Are you looking for example code of a client or a server?
 
If you are looking for a sample server the smart_home_server_linux sample is the most up to date and complete sample for the server. Unfortunately we don’t have a client sample to interact with this server it is typically exercised by the certification and testing tool (CTT).
 
If you are looking for sample clients I would suggest checking out the temp_sensor_client_linux
 
 
The simpleclient will talk to the simpleserver sample.  However these samples are not using standardized resources for that reason I typically don’t recommend them as a samples but they are some of the few samples that we have both a client and server that talk with each other.
 
Hope this helps.
 
George
 
From: iotivity-dev@iotivity.groups.io <iotivity-dev@iotivity.groups.io> On Behalf Of elizabethnathaniaw93@...
Sent: Wednesday, February 19, 2020 8:29 AM
To: iotivity-dev@iotivity.groups.io
Subject: Re: [dev] Iotivity Client
 
Hi Clarke,
Thanks. I've downloaded the OTGC Linux.
Also, is there any example in C for the client?
In iotivity-lite source in github, there are several examples of the client in C, but I couldn't found an example when it runs get or post function (e.g. turn on/off the light, get light state) from the client that is written in C file.



elizabethnathaniaw93@...
 

Hi George and Clarke,
Thanks for the response!
Also thanks to Clarke, Yes, I've tried your examples to build an iotivity server as you gave me that before. I've built Iotivity server on my Raspberry Pi with enviro phat as the sensor.

Now, I'm looking for a client example for communicate with smart_home_server_with_mock_swupdate, because my research is try to implement OCF firmware update protocol. I've read both smart_home_server_with_mock_swupdate code and OCF FU protocol documentation (OCF 2.0.3 core and security specifications), it needs a client to trigger the firmware update process (according to OCF FU protocol documentation). That's why I want to learn the other client and server example first before I can make the client for trigger the FU process.

I've tried the simpleclient and simpleserver, but they didn't communicate. In simpleclient code, the client should do observe then get the light state from simpleserver. But, it stopped after send and received coap messages.
Do I need to run onboarding_tool first and onboard the server and client before it can communicate each other (for example: client get the resource from the server)?

And for gcc, what version that compatible?


Clarke Stevens
 

Elizabeth,

Yes, you will need to onboard the server before the client and server will communicate. You probably know more than I do about the update specification. I haven’t built an example with it yet. Wouter is the expert on the update specification. Kishen is the expert on simpleserver and simpleclient, but I think George has also built those many times.

Thanks,
-Clarke

On Feb 23, 2020, at 10:43 PM, elizabethnathaniaw93@... wrote:

Hi George and Clarke,
Thanks for the response!
Also thanks to Clarke, Yes, I've tried your examples to build an iotivity server as you gave me that before. I've built Iotivity server on my Raspberry Pi with enviro phat as the sensor.

Now, I'm looking for a client example for communicate with smart_home_server_with_mock_swupdate, because my research is try to implement OCF firmware update protocol. I've read both smart_home_server_with_mock_swupdate code and OCF FU protocol documentation (OCF 2.0.3 core and security specifications), it needs a client to trigger the firmware update process (according to OCF FU protocol documentation). That's why I want to learn the other client and server example first before I can make the client for trigger the FU process.

I've tried the simpleclient and simpleserver, but they didn't communicate. In simpleclient code, the client should do observe then get the light state from simpleserver. But, it stopped after send and received coap messages.
Do I need to run onboarding_tool first and onboard the server and client before it can communicate each other (for example: client get the resource from the server)?

And for gcc, what version that compatible?


George Nash
 

Elizabeth,

 

As Clark said the client server will not communicate unless they have been onboarded.  This can be done using the OTGC tool developed by OCF. Sorry I don’t know the link to the tool.  Or you can use the onboarding_tool that is part of iotivity-lite.  The onboarding_tool is a used by the development team to test and verify the onboarding and provisioning features. It is not the most user friendly.  The README.rst document has a set-by-setp guide for using the onboarding tool to onboard and provision a server and client. (search for the “Simple Step-by-Step guide for onboarding and provisioning” section) The steps in that document is what I use almost every day when testing servers and clients.

 

George

 

From: iotivity-dev@iotivity.groups.io <iotivity-dev@iotivity.groups.io> On Behalf Of Clarke Stevens
Sent: Sunday, February 23, 2020 10:54 PM
To: elizabethnathaniaw93@...
Cc: iotivity-dev@iotivity.groups.io
Subject: Re: [dev] Iotivity Client

 

Elizabeth,

 

Yes, you will need to onboard the server before the client and server will communicate. You probably know more than I do about the update specification. I haven’t built an example with it yet. Wouter is the expert on the update specification. Kishen is the expert on simpleserver and simpleclient, but I think George has also built those many times.

 

Thanks,

-Clarke



On Feb 23, 2020, at 10:43 PM, elizabethnathaniaw93@... wrote:

 

Hi George and Clarke,
Thanks for the response!
Also thanks to Clarke, Yes, I've tried your examples to build an iotivity server as you gave me that before. I've built Iotivity server on my Raspberry Pi with enviro phat as the sensor.

Now, I'm looking for a client example for communicate with smart_home_server_with_mock_swupdate, because my research is try to implement OCF firmware update protocol. I've read both smart_home_server_with_mock_swupdate code and OCF FU protocol documentation (OCF 2.0.3 core and security specifications), it needs a client to trigger the firmware update process (according to OCF FU protocol documentation). That's why I want to learn the other client and server example first before I can make the client for trigger the FU process.

I've tried the simpleclient and simpleserver, but they didn't communicate. In simpleclient code, the client should do observe then get the light state from simpleserver. But, it stopped after send and received coap messages.
Do I need to run onboarding_tool first and onboard the server and client before it can communicate each other (for example: client get the resource from the server)?

And for gcc, what version that compatible?

 


elizabethnathaniaw93@...
 

Hi Clarke and George,
I see. Thank you!
I've tried the onboarding_tool from iotivity-lite github and follow the step in README.md. It works. The simpleserver and simpleclient can communicate.

Do you have any idea if I want to observe the pstat resource from client? Do I need to change the endpoint at discovery function, I mean the rt, to oic.r.pstat?


George Nash
 

You should be able to observer the pstat resource from the client.

 

Discover the oic.r.pstat resource. From the discovery callback call oc_do_observe(…) using the server information that you got from the discovery callback.

 

Check the permissions for the oic.r.pstat resource to see if it has notify permissions. I am not sure what the default permissions for that resource is. If it does not have the correct permissions you should be able to update the permissions using the onboarding_tool.

 

It really should be as simple as that.

 

George

 

 

 

From: iotivity-dev@iotivity.groups.io <iotivity-dev@iotivity.groups.io> On Behalf Of elizabethnathaniaw93@...
Sent: Thursday, February 27, 2020 9:45 AM
To: iotivity-dev@iotivity.groups.io
Subject: Re: [dev] Iotivity Client

 

Hi Clarke and George,
I see. Thank you!
I've tried the onboarding_tool from iotivity-lite github and follow the step in README.md. It works. The simpleserver and simpleclient can communicate.

Do you have any idea if I want to observe the pstat resource from client? Do I need to change the endpoint at discovery function, I mean the rt, to oic.r.pstat?


elizabethnathaniaw93@...
 

George,
Thanks!
What I did was, I use simpleclient and simpleserver example.
I edited the simpleclient --> in do_ip_discovery, I discover the oic.r.pstat. Then, in discover callback function I could get the coaps endpoint and port for /oic/sec/psat/ resource. Inside discover callback function, I put oc_do_observe(...) and call the handler. Here I create new function called observe_pstat that oc_do_observe will call. But, in my function observe_pstat, when I want to get the data payload, it was null. I don't know why? Should I put the get handler in simpleserver for get_pstat? Is it okay to have 2 get handler for 1 resource? 1 for get_light and 1 for get_pstat?

In the other hand, I've read the oc_pstat.h, It has get function to get the pstat attribute (cm, tm, etc). But, I have no idea how to use it.


George Nash
 

Without a little code I am a little lost why your payload would be null.

 

> Is it okay to have 2 get handler for 1 resource? 1 for get_light and 1 for get_pstat?

 

As far as I know you can put as many get handlers as you would like.  It is quite reasonable to have 1 for light and 1 for pstat.

 

I am a little curious what you are trying to achieve.  The oc_pstat.h header is considered an internal API and should not need to use IoTivity-lite. However, most developers will not even need to know about the pstat resource in their daily use of IoTivity-lite so you may have a reason you are tying to use the internal API that was not considered by us.

 

If you can expand on your question I will see if I can help.

 

George

 

From: iotivity-dev@iotivity.groups.io <iotivity-dev@iotivity.groups.io> On Behalf Of elizabethnathaniaw93@...
Sent: Friday, February 28, 2020 9:37 AM
To: iotivity-dev@iotivity.groups.io
Subject: Re: [dev] Iotivity Client

 

George,
Thanks!
What I did was, I use simpleclient and simpleserver example.
I edited the simpleclient --> in do_ip_discovery, I discover the oic.r.pstat. Then, in discover callback function I could get the coaps endpoint and port for /oic/sec/psat/ resource. Inside discover callback function, I put oc_do_observe(...) and call the handler. Here I create new function called observe_pstat that oc_do_observe will call. But, in my function observe_pstat, when I want to get the data payload, it was null. I don't know why? Should I put the get handler in simpleserver for get_pstat? Is it okay to have 2 get handler for 1 resource? 1 for get_light and 1 for get_pstat?

In the other hand, I've read the oc_pstat.h, It has get function to get the pstat attribute (cm, tm, etc). But, I have no idea how to use it.


elizabethnathaniaw93@...
 

Hi George!
Okay, I will explain first why I need to know the pstat resource. So, as I said before, I want to create a client that can communicate with the smart_home_server_with_mock_swupdate file in iotivity-lite GitHub. Because I want to implement the OCF firmware update protocol. My reference is in the OCF Security and OCF Core documentation version 2.0.3. In OCF Core docs, they provide a firmware update protocol (I put the picture below). After I read the swupdate.c, oc_swupdate_internal.h in API folder, I try to see the connection between the code and the protocol.
So far, what I understand is: (please if you know or anyone knows more about this correct me. I've created a post about iotivity update in this mailing list, but no one reply yet.)
 - the code has implemented the protocol from 'new firmware available' until the 'upgrade image' part. It means I need to make a client to 'observe device' and 'software upgrade initialization' part.
- In 'observe device', the client needs to observe the softwareupgrade and pstat resource.
That's why I need to observe the pstat.cm state.



George Nash
 

I think I understand why you are trying to observer the `pstat` resource.  You are trying to track the ‘cm’ property.  I don’t think you need to track that the IoTivity-lite famework should be tracking all of that for you.

 

To add software update to your code you should only require the functions found in the oc_swupdate.h header file.

 

You can reference the smart_home_server_with_mock_swupdate.cpp.  I went to your past email and it seems you don’t know how to do the following

 

  • You don't know how to trigger the software update resource?
  • Also how to set the URL for download the firmware update?

 

I will do my best to answer those two questions. Note, I personally have not done this I am giving my best answer to those questions if I get the answer wrong I hope Cunningham’s Law will kick in and someone will correct me.

 

As best I can tell you trigger the software update resource from a client. Looking at the specification for oic.r.softwareupdate there are 3 properties that you can write to from the client. They are `purl` (package url, the source of the software package, might be an HTTPS or a CoAPs URL), `swupdateaction` (Scheduled action to do a software update) , and `updatetime` (Scheduled time).

 

 

So you would discover the oic.r.softwareupdate resource to find the endpoints for the server.

Then you would call oc_do_post to call filling out the 3 properties listed above.

 

Call POST on the oic.r.softwareupdate (check if a newer software version is avalible)

  • “purl”: https://myvender/newversion, “swupdateaction”: “isac”, “updatetime”: "2020-03-03T14:30:00Z"  (“isac” means initiate software availability check)

 

This will trigger the swupdate_impl.check_new_version callback on the server

 

I am not sure how the client finds out the result of this call.

 

Call POST on the oic.r.softwareupdate (download and verify the software version is valid)

  • “purl”: https://myvender/newversion, “swupdateaction”: “isvv”, “updatetime”: "2020-03-03T14:31:00Z" (“isvv” means initiate software version validation)

 

This will trigger the download_update callback on the server.

 

Once again I am not sure how the client finds out the result of this call.

 

Call POST on the oic.r.softwareupdate (initiate the software update)

 

This will trigger the actual update

 

Other than the upgrade action I am not sure if the “updatetime” is used for any of the other actions.

 

I hope this helps you get started.

 

George

 

 

 

 

 

 

From: iotivity-dev@iotivity.groups.io <iotivity-dev@iotivity.groups.io> On Behalf Of elizabethnathaniaw93@...
Sent: Tuesday, March 3, 2020 9:53 AM
To: iotivity-dev@iotivity.groups.io
Subject: Re: [dev] Iotivity Client

 

Hi George!
Okay, I will explain first why I need to know the pstat resource. So, as I said before, I want to create a client that can communicate with the smart_home_server_with_mock_swupdate file in iotivity-lite GitHub. Because I want to implement the OCF firmware update protocol. My reference is in the OCF Security and OCF Core documentation version 2.0.3. In OCF Core docs, they provide a firmware update protocol (I put the picture below). After I read the swupdate.c, oc_swupdate_internal.h in API folder, I try to see the connection between the code and the protocol.
So far, what I understand is: (please if you know or anyone knows more about this correct me. I've created a post about iotivity update in this mailing list, but no one reply yet.)
 - the code has implemented the protocol from 'new firmware available' until the 'upgrade image' part. It means I need to make a client to 'observe device' and 'software upgrade initialization' part.
- In 'observe device', the client needs to observe the softwareupgrade and pstat resource.
That's why I need to observe the pstat.cm state.



elizabethnathaniaw93@...
 

George,
Yes, Thank you! That really helps me to have a better understanding of the code flow.
So, today I tried to observe oic.r.softwareupdate resource, get the endpoint and port, then oc_do_post the first step (isac) to check it will work or not. But it didn't work. And after I print the result of the oc_status code is 6 which means OC_STATUS_UNAUTHORIZED. Is it because of the permission of softwareupdate resources? Since it is the internal iotivity-lite framework?
I've tried to use onboarding tool, choose option provision ACE2, set the resource href to /sw, give RUN permission. But it didn't work, I think I've done it wrong.
Maybe you can help me how to give authorization to the client to interact with pstat and softwareupdate resource or how to set the permission of the internal Iotivity-lite framework (such as pstat and softwareupdate resource)?.


George Nash
 

There is no RUN permission so I am a little confused.

 

The permissions are CREATE, READ, UPDATE, DELETE, NOTIFY  (CRUDN)

 

READ will let clients read the resource properties.  (e.g. oc_do_get)

UPDATE will let clients update (write) the resource properties (e.g. oc_do_push)

NOTIFY will let clients receive a notifications.

 

CREATE enable a client to create a new resource on the server

DELETE enable a client to delete an existing resource from the server

 

You are unlikely to need CREATE and DELETE.

 

 

Your error OC_STATUS_UNAUTHORIZED is almost always a permissions error so it seems likely that the ACE2 is not setup correctly or you may have forgotten to pair the server and client.

 

If you use the instructions found in the top level README instead of selecting

[2]: All NCRs with >=1 secured endpoint '+'

Try selecting

[1]: All NCRs '*'

 

Set the READ, UPDATE, and NOTIFY permission.  Using wildcard `*` with this permission opens the server up even to un-trusted clients but its unlikely to be a problem while you are just getting started. Once you have the client/server actually working mess around the ACE2 permissions to make it more secure.

 

George

From: iotivity-dev@iotivity.groups.io <iotivity-dev@iotivity.groups.io> On Behalf Of elizabethnathaniaw93@...
Sent: Wednesday, March 4, 2020 8:33 AM
To: iotivity-dev@iotivity.groups.io
Subject: Re: [dev] Iotivity Client

 

George,
Yes, Thank you! That really helps me to have a better understanding of the code flow.
So, today I tried to observe oic.r.softwareupdate resource, get the endpoint and port, then oc_do_post the first step (isac) to check it will work or not. But it didn't work. And after I print the result of the oc_status code is 6 which means OC_STATUS_UNAUTHORIZED. Is it because of the permission of softwareupdate resources? Since it is the internal iotivity-lite framework?
I've tried to use onboarding tool, choose option provision ACE2, set the resource href to /sw, give RUN permission. But it didn't work, I think I've done it wrong.
Maybe you can help me how to give authorization to the client to interact with pstat and softwareupdate resource or how to set the permission of the internal Iotivity-lite framework (such as pstat and softwareupdate resource)?.


elizabethnathaniaw93@...
 

George,
Ups, sorry my bad. Missing separator. I mean R,U,N (Read, Update, Notify).
Yes, I've followed the step on README, and also I tried to change the option to number [1]: All NCRs '*'. But still Unauthorized. Then, today I try to fill the href resource with /sw (softwareupdate URI). Turns out it worked! I can get the oic.r.softwareupdate property values. I put the screenshot of my server's ACE. In the last 2 ACE, I put the href.

Another problem is, after I successfully observe and get the values when I try to oc_do_post, the oc_status code was 11 (OC_STATUS_NOT_ACCEPTABLE) or 17 (OC_STATUS_NOT_AVAILABLE). This is my code for oc_do_post:
1  if (oc_init_post(swupdate_uri, swupdate_server, NULL, &post_swupdate, HIGH_QOS, NULL)) {
2     oc_rep_start_root_object();
3     oc_rep_set_text_string(root, purl, "http://127.0.0.1");
4      //oc_rep_set_int(root, swupdateaction, 0);
5      //oc_rep_set_text_string(root, updatetime, "2020-03-05T20:00:00Z");
6      oc_rep_end_root_object();
7      if (oc_do_post())
8        PRINT("Sent POST request\n");
9      else
10        PRINT("Could not send POST request\n");
11  }

When I comment line 4 and 5, the oc_status code was 11. Then, when I uncomment line 4 and 5, the oc_status code was 17. Any idea why this happens?