How to connect Arduino to Raspberry pi via Ethernet shield!

hi , i’m really new to openhab ,just started last week

installed OH2 on my raspberry pi and mqtt , everything working fine.

but I want to connect arduino Mega to my raspberry pi to send sensors data and I have Ethernet shield W5100
… is that possible ? if yes …How ?

or any other approach ?

Depends on how you want to do it. You can do this

Arduino -> openHAB via POST (Arduino pushing data)
OpenHAB <- Arduino via GET (openHAB pulling data)
Arduino <–> MQTT <–> openHAB (two way)

1 Like

Arduino <–> MQTT <–> openHAB

Because I already setup the MQTT in my Raspberry pi …

But I didn’t no how to implement that in my project… can you give an example ?

Are you familiar with MQTT and/or Raspberry at all ?

If not,

1 Like

I’m familiar with both ,
I know the Concept of MQTT and it’s purpose

Butt I don’t know the way to implement the MQTT

Thanks man I will try what you suggest !

Tell us what you have started/tried so far and we can start from there.

Thanks… i will try that

I did :

  • Install Openhab 2 on my raspberry pi , and create site map + items + rules …I tried to control an LED local and remote using my raspberry pi GPIO and It is working .

  • Setup MQTT on my raspberry pi tested and working .

  • I got an Arduino mega 2560 + Ethernet shield , I’ve added some sensors and write and upload sketch to get input from the sensors and use them to trigger some LED for testing

Now I want to take an input form the sensor and write some rules based on that input …

For example I have motion sensor (PIR) , I want to control a light 
 if there is motion the light turns on 
 else light off , and I want to update the light Item to on or off 

another Idea is to see if the light switched by the user via openhab and sensor delay for 5 min then will push notification to the user "light is on for some time and there is no one in the room , you better turn it off "

Ok thanks for the info. So now, you have rPi, openHab and the Arduino. Is your Arduino updating your MQTT topic? Is it publishing the sensor data?

When your Arduino GPIO is triggered (interrupt) or you’re polling (digital read), as soon as you have the data, you need your Arduino to publish that data to your MQTT. Assuming your openHAB is subscribed, you should be able to make a rule for it. Can you post your item and rules, if any?