lukedukeus / esp32-bacnet-master-v5.01

9 stars 8 forks source link

Read and write on another BACnet devices #2

Open innamidome opened 9 months ago

innamidome commented 9 months ago

Hi, Thanks a lot for your job. I'd like to read and write to another BACnet device. Do you have any idea if it could be possible? and if so, how? thank you. Inna

lukedukeus commented 9 months ago

If you want to do that from your computer, you can use a bacnet network browser, but if you want to do it from the esp32, you will have to use the datalink_send_pdu(address, npdu_data, pdu, pdu_length) function to send command / data to a specific address.

innamidome commented 9 months ago

Yes, I was talking about reading or writing from the ESP32. So let's say, I'd like to write the value 23 on analog value number 1 of BACnet device number 3, how could I use the function datalink_send_pdu ? Would you have an example by any chance? Thks

lukedukeus commented 9 months ago

I dont have an example. I would suggest looking at wp.c here which works with encoding / decoding write property requests.

I think the way to go about it would be first to construct a BACNET_WRITE_PROPERTY_DATA that contains info about the property you want to write, then use wp_encode_apdu to encode the write request to a buffer, then use datalink_send_pdu to send the packets out the door.

I havent done it before, and am not super familiar with bacnet, so I'm not sure if this is the correct way. One problem you might run into is that you have no clue what part isn't working if you are not able to write a property. You might try logging what your esp32 recieves as a bacnet server when you use a bacnet client (on your computer for example) to write a value, then replay the message as a client.

CMD10M commented 9 months ago

Thanks for asking the question @innamidome. I am also hoping to perform reading/writing functionality from a ESP32 board to other BACnet devices over BACnet/IP.

I was under the impression that this project is capable of performing those functions. @lukedukeus Could you please explain the current functionality of this project and if there are any other projects you know of that can perform reading/writing functionality from a ESP32 board to other BACnet devices over BACnet/IP

lukedukeus commented 9 months ago

This repo is an bacnet server using this library, Implemented in ESP-IDF. Under the ports directory, the bacnet-stack library has an example for esp32 that does the same thing, but written using platformio. Right now it is designed to join the esp32 to a network, then act as a bacnet server - or a device that sits on the network, that you could read / write values to.

The library this uses (bacnet-stack) is capable of handling read and write requests, as well as sending them. This example project just shows handling requests, not sending them out. If I get some time this week, I will put together an example of sending read / write requests

CMD10M commented 9 months ago

@lukedukeus thank you very much for your help!

CMD10M commented 9 months ago

this library

I tried using the (bacnet-stack) library but couldn't get it to run on my ESP32 board. Would you be able to help guide me on how to get that functionality using your repo? Or is this what you're planning to work on this week, if you get some time?

lukedukeus commented 9 months ago

this library

I tried using the (bacnet-stack) library but couldn't get it to run on my ESP32 board. Would you be able to help guide me on how to get that functionality using your repo? Or is this what you're planning to work on this week, if you get some time?

I wasn't able to get it working either, thats why I created this repo, which is mostly the same code, just on top of ESP-IDF. I also had to look a the windows port, as the network apis are similar between esp32 / windows

CMD10M commented 9 months ago

this library

I tried using the (bacnet-stack) library but couldn't get it to run on my ESP32 board. Would you be able to help guide me on how to get that functionality using your repo? Or is this what you're planning to work on this week, if you get some time?

I wasn't able to get it working either, thats why I created this repo, which is mostly the same code, just on top of ESP-IDF. I also had to look a the windows port, as the network apis are similar between esp32 / windows

Ok. I am a beginner with C and BACnet but please let me know if theres anything I can do to help with developing the read/write requests for this sample code.

lukedukeus commented 9 months ago

@CMD10M @innamidome see the updated code / readme. I have it setup so the esp32 is a server, but also a client that can write properties. You will have to play around with the kconfig settings to get it working, and the example is pretty sloppy, so you may have to start / restart the esp32s a few times to get it working. Most of this sample was created from here.

innamidome commented 9 months ago

@lukedukeus Sounds good ! I'll try this next week ;). Thanks for your reactivity.

CMD10M commented 9 months ago

@lukedukeus Thank you very much! Is there a 'server only version' where we don't have to define the downstream devices or other BACnet devices on the network. Rather, they can discover us but we can still do read/write in a more passive way?

Instead of a client that is more active and does active requests to other BACnet devices?

lukedukeus commented 9 months ago

Sure, you can comment out the server task. Sending an i-am should get you what devices are on the network. I don't have any examples, but take a look at the bacnet-stack library examples. You could also look at yabe, to see how it discovers devices.

CMD10M commented 9 months ago

Ok thank you! Also, is it possible to use platformIO with this repo?

lukedukeus commented 9 months ago

Im sure you could get it to work with some adjustment, right now it is using ESP-IDF

CMD10M commented 9 months ago

Thank you so much for all your help! Ill work on it over the next few days and see where I end up!

CMD10M commented 9 months ago
Screenshot 2023-11-24 at 9 54 41 AM

I have the repo downloaded and I am using VS Code and the ESP-IDE extension but am having issues building the project and uploading it to my ESP32 board. Could you please point me in the right direction on how to upload this project to my board?

Thank you!

lukedukeus commented 9 months ago

It looks like ESP-IDF build system is not installed. Do ctrl+shift+P, then configure ESP-IDF extension. Try following the instructions here: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/

CMD10M commented 9 months ago

Awesome! Got the project flashed onto my board. If I want to change the code to try and read/write data from a raspberry pi acting as a BACnet device, what files should I change in the 'main' folder?

Screenshot 2023-11-24 at 1 32 09 PM
lukedukeus commented 9 months ago

Take a look at client_task.c, and changing the device id to write to a different device on the same network. Yabe is very helpful for discovering what devices are on your network.

CMD10M commented 9 months ago

Thank you. I have a Raspberry Pi acting as a BACnet server and I got the ESP32 board connected to my local wifi by flashing your code onto my board. I am trying to send a simple WhoIs to the Raspberry Pi BACnet server to connect it with the ESP32 board but am unsuccessful. The Wifi connection seems to be 'looping' when I monitor the code. Would you have some time this week to schedule a virtual meeting to discuss this project? I would really appreciate your help.

Thank you.

Screenshot 2023-11-25 at 8 07 07 PM
lukedukeus commented 9 months ago

Sure, send me an email at vanzweden1@gmail.com, and we can schedule something.

CMD10M commented 9 months ago

Ok! Thank you! I’ll send an email out tomorrow.