Intro to farmOS v2 sensor integration

Could someone please give a decent example of sensor integraton in v2?
Maybe for simplicity without tinkering with sensors, an example that logs cpu-temp would be a nice place to start?

2 Likes

I setup a sensor for V2 last night.
Sensor is in Home Assistant and passed to farmOS with NodeRed. I can provide a bit more detail on what I’ve done when I get time later if that is of help to you. I haven’t tried to monitor CPU temperature though, but if NodeRed can read it, then the process will be much the same.

NodeRed CPU example. node-red-contrib-cpu (node) - Node-RED

Sample code for a function node to convert temperature payload to JSON.

var temp = msg.payload;
msg.payload = {temperature: temp}
return msg;

finally send to your farmOS with a WWW request node, using Post Method.
to
https://your_farmOS_Address/asset/XXXXXXXXXXXXXXXXX/data/basic?private_key=your_private key (you can get your complete URL including keys after creating the sensor in farmOS under Developer information)

2 Likes

Thanks for sharing that @Farmer-Ed !

For what it’s worth, the old guide for farmOS v1 is still available here, and although some of the specifics are different in v2, the basic principles are the same: Sensors - farmOS.org

But what @Farmer-Ed said is the most important part :slight_smile: …

finally send to your farmOS with a WWW request node, using Post Method .
to
https://your_farmOS_Address/asset/XXXXXXXXXXXXXXXXX/data/basic?private_key=your_private key (you can get your complete URL including keys after creating the sensor in farmOS under Developer information)

1 Like

There is no developer info in v2 as far as I can see. Only in v1. And the url seems different in v1.

1 Like

There is, but I think you need to add a data stream first and save it. Then go back and view the sensor and the developer option is available with your URL.

1 Like

Yea one key difference between v1 and v2 is that v2 introduced the concept of a “Data stream” - which is just a formalized entity to represent a single stream of data. So one sensor may have one or more data streams associate with it (eg: if your sensor is measuring both temperature and humidity).

@paul121 built a lot of the v2 sensor architecture, so he might be able to provide more insights, but that’s the general structure. :slight_smile:

This would be a great candidate for a community guide! farmOS blog/tutorials

1 Like

@mstenta
I’ve twisted my brain but I can not find anything that lets me set up a stream.
I must be missing somthing. Nothing related to stream, and no developer info.
Could it be something missing in the hosted FarmOS?

1 Like

@pat Ah ha! @pat you’ve discovered a bug! :slight_smile:

It is not a hosting bug, although that’s a bit related…

farmOS is not assigning the permission to create new data streams properly. It should be making that permission available to Manager and Worker roles, but none of them have access it seems. In @Farmer-Ed’s case, since he is self-hosting, he has the administrative user access which has ALL permissions to everything.

I will file a bug report and get it fixed for the next release!

In the meantime, if you message me your farmOS URL I will override the permissions to give you access. :slight_smile:

2 Likes

Aha… That makes sense. I wasn’t me then.

1 Like

Nope! It wasn’t you. And thanks for sticking with it so we could find this bug!

I’ve enabled the necessary permissions on your Farmier-hosted instance, and will work on fixing the bug for the next release. Good luck setting up your data streams! Let me know if you run into any other issues… :+1:

Thanks. Worked now. We’ll do some testing…

1 Like

Nah… I can see developer info now, and curl example.
But when I run curl in terminal, I get a bunch of HTML-code.
@mstenta I’ll PM my farmos url. just in case.

Looks like this in a browser.:

Breadcrumb

  1. [Home](file:///)

Access denied

You are not authorized to access this page.

  • [Reset your password](file:///user/password)

Powered by farmOS | Hosted by Farmier
Subscription Agreement | Privacy Policy

1 Like

Oh sorry @pat I forgot: Farmier does not allow sensor data for free trials. You’ll have to activate your subscription.

I finally managed to send data to a sensor stream on a selfhosted docker.

I activated my subscription and I still get HTML tags when I run the CURL example.
Is this a bug, or do I just wait for some magic to happen with my subscription?

I get <Response [403]> error when I do a print(x) after this line.
x = requests.post(url, data=str(myobj), headers=header)

1 Like

@pat Send me a PM and I’ll help you figure it out. You are the first to test out sensor data for farmOS v2 on Farmier, so it’s entirely possible that there are still bugs on my end to iron out. Happy to help get it working with you! :slight_smile:

Hi @Farmer-Ed
Finally got my FarmOS up and running with the sensor part working.
Was able to setup a flow that sends cpu load to FarmOS when the load is above 50%

Skjermdump fra 2022-02-09 08-57-05

This was really cool

2 Likes

@pat great that it worked out for you.

Node-Red really can simplify the process and it is far from limited to passing messages from sensors.

So what sort of sensors are you going to monitor?

1 Like

Yep. I can see that Node-Red simplifies it a bit. (Once you get the hang of it)

I have a pig barn where I intend to monitor temperature and moisture. There are 6 rooms. Not sure if I’ll monitor all areas tho. I would also like to monitor the pigs water usage.
Guess I’ll need some mesh network for the sensors.

And maybe some soil temperature.
Would also like to log rainfal during season…

But one step at a time.

2 Likes

BTW, @Farmer-Ed I read that you authenticated to FarmOS from HomeAssistant. I’m not there yet.
Have you found a way to authenticate within Node-Red?
I’d like to use Node-Red more before walking the HomeAssistant road.

1 Like