Which communication protocol should I use?

Hi!

I'm making my own home automation system. I've already had some success, but I don't know what communication protocol to use.

What I want to achieve:
I want to connect a raspberry pi and multiple ESP8266 MCUs in a bus or bus-like structure. There would be no master or slave devices as I'd like to use the same wires to connect the pi, the LED-drivers and the button panels (the buttons would be configureable).

What are my ideas:
RS485 - i'd like to add more then 32 devices, but I cannot find ic's that are cheap and capable of this. Also I have no experiences with this standard, but I believe in it.
RS232 - I was wondering if I could use some MAX3232 ICs and set them up as repeaters (as there are 2 TTL-RS232 converters in each IC) and use 1 of the RX pins to connect to the MCU, but I don't think, there's a way to send back data. If it's possible, then I'd like to use this method as there's no problem with timing because this is not a bus structure.
I2C - I've not found any good libraries for I2C, because i'd like to send strings, that are longer than 32 bytes (the limitation of the standard wire library) and also I'd like to transfer data through ~100m of cable, so some kind of level converter would be good.

I'd like to use some of this interfaces, but I'm open to new ideas. Also I want to develop my own data format because that's not a big problem.
As for the RS485, it would be nice to have an example code, because if multiple devices try to send data at the same time then it's not fun.

If something is not clear, just ask it, I'll explain.
My use of english may not be perfect, sorry for that.

EDIT: If you'd like to know more about the project (eg. the programs on the pi), please contact me in private message. I appreciate every little bit of help.

Interesting project. What information will be exchanged? Capacity needed? RS232 and a Token ring network is one old horse. Ethernet style is another.
Of course You can start out of hardware and see what You can do. Preferable is to start from the logical aspect, what You want to achieve.

If you are using ESP8266s why not just use WiFi?

I think the idea of not designating a master (or a server) will make the whole concept a lot more complicated.

...R

Railroader:
The information is highly dependent on the device type.
eg.:
led drivers - red, green, blue and white values or requesting their current state
buttons - at first the pi would send them the commands for the individual buttons (maximum of 4 or 6 buttons/device) and then the device would remember it.
I'm also going to make temperature, humidity and light sensors, which will have programmable trigger values. also their data will be logged.

What do you mean "capacity"?

Yes, starting from hardware, the RS232 is easier, but the RS485 is made for similar applications.

Robin2:
I don't want to use Wifi, because it would make a lot of interference so wires are mor reliable.
I use ESP8266s because I want to be able to update the software on them remotely if needed.
Also they're really cheap and easy to implement on PCBs.

Ok. it looks like a system where different units exchange data "now and then". Then there will not be any time/capacity problem for messages to be sent and received, no "rush hour, no traffic jam". I take my hat off for using wires. Built a new house 35 years ago and thought about installing cabeling used for private projects…..

Actually I'd like to use powerline communication, but it's expensive and there's no such tiny hardware I need.

Correct. There will be no rush hour.

I can actually do it by cable, because my dad used to work for a telecommunication company and he brought home a lot of wires that would have been thrown away.

And if it's complete then I'll maybe launch it as a product. If you're building a house, then the cost of wires is not so big deal.

Robin2:
If you are using ESP8266s why not just use WiFi?

Seconded!

You don't already have WiFi? Wireless can be more reliable than wires. You can never accidentally cut the wire during future renovations.

Using cables and asking for protocoll Ethernet looks like good unless You want a master node to be conducting the music, running a Master/Slave system.

Yes, I have wifi, but in one corner of the house there is barely any signal strength.
And then I won't have to configure all my devices to connect to the wifi network. I just plug them in and they send a login message and done. They are ready to use. Also I wouldn't like if ~30-40 devices just made huge interference mess.

I'd like to connect to the internet via the raspberry pi. The others would be connected with i2c, or RS485, or some kind of modded RS232.

I2C has its limitations regarding the length of the bus wire. Modded RS232..... RS232 is a Point to Point concept… RS485 I don't know much about….

RS485 is designed from the beginning as a multi-drop system. You can do the same with RS232 but it is slightly more difficult to ensure that slaves don't hold the line when they aren't transmitting. In both cases, MODBUS is a useful protocol.

I2C is completely unsuitable for local-area networking.

SPI is better, but not quite as simple to cable.

CAN bus might be useful but I've never used it.

Have a look at the JeeNode system. There are some great ideas there.

Yes, CANBUS is basically a protocol for the RS485 standard. Are there any good libraries for RS485/CANBUS with collision avoidance?

RS485 is probably simpler to use than Canbus

Is there any really good library for RS485?

I found the ATA6660 CAN transciever, which looks good to me. It's a 5V supply, 3V3 level IC, it has no DE and RE pins, it's easier to implement, I think. Also it's an open-drain configuration so there's no way to make a short circuit by transmitting with multiple devices at the same time.

Also it's just the hardware, so it's possible to write a library for myself.
And it would be easier to implement with the raspberry pi.

ATA6660 datasheet: http://www.mouser.com/ds/2/268/doc4582-1065831.pdf

have a look at How-to-Use-Modbus-With-Raspberry-Pi and Canbus library
also try a web search for raspberry pi rs485 library

Nick Gamman has an article on RS485. There is a link to a library as well.

If there isn't much traffic, I would let a master poll the slaves. It's possible to use a multi-master setup, either with collision detection or by giving each master a time-slot.

See arduino uno - RS485 Multimaster Communication with collision avoidance - Arduino Stack Exchange for both principles.

horace:
I need to design my own hardware, because of space limitation. My only problem is the interface and the software. But anyways, thank you, these are interesting articles to read!

sterretje:
Thank you, these articles look useful. Do you think that polling ~200 slaves would be possible without significant delays: For example; I push a button on slave 167 to turn on LEDs (eg. slave 78). Isn't there a significant delay if I continously poll all the slaves?

Also I have an idea with RS232. All the devices would act as repeaters. If a node gets back its own message, then it terminates Does it seem legit?

what microcontroller board are you using for the nodes?
could you use Arduino Pro minis with RS485

I'd like to use ESP8266s. They're cheap and easy to implement on PCBs.

if you are using ESP82266s devices why not set up a ESP8266 mesh? this should ovecome the problem of WiFi transmission distance limitations