Been brainstorming for a while a project I want to start on. It's not too complicated and I'm sure there are many like it but I still want to make my own. Essentially it will be a home automation/monitoring system where you can have various sensors/controllers throughout the house, or even across multiple buildings. My goal is to make it very plug and play, so you would start with the master which would be a PC, it can be a raspberry pi, basically anything that runs Linux. It would run software that then talks to the central hub which talks to all the sensors. Then you would have the central hub which would be essentially an arduino/MCU board connected via USB (serial interface) to the PC. The central hub would then have various sensors, or even other hubs connected to it. This is where the protocol comes in. My goal is to make this super plug and play which is why I want a custom protocol. You plug in any device you can think of that speaks this protocol, and it would just show up as a new device and then you can configure it and do what you want from there. A device can be as simple as a dry contact i/o board, or a single temp sensor, or another hub, or even something super specific like a custom hvac unit or something (actuators, sensors etc to control/read). Goal is to make it super expandable. You add a device and it would essentially present input and output and other similar parameters. It would be up to the central controller (on the PC) to decide what to do with those controls.
So I guess my question is, what is a good reading resource on designing a protocol like this? Essentially communicating between other MCUs over potentially long distances. (let's say, up to 1km but probably much less) I want to read up on stuff like different ways of doing it, such as doing a single wire bus, or a two wire bus where you have a clock signal, twisted pair vs not, etc... There's many ways to go about it I'm sure.
I'm leaning towards a 4 wire setup. You have your ground, +5v, a clock signal, and then the com wire, which would use 0/5v to speak in binary. The actual devices would use 2 pins for this, an input and an output, with appropriate diodes etc to ensure they don't screw with each other. Only two devices would be able to speak at once so it would use a sort of polling system. The clock would only go on when it's that device's turn to speak. This is very simple rough idea mind you. Basically open to suggestions on what to read up on while designing this. I'm sure there's lot of pros/cons I need to consider on various ways of doing it, such as how far I can go or how many wires I use up.
I would probably lean towards atmega just because I have lot of those chips, I only really know how to do arduino at this point but I would probably want to learn how to do it more "raw" to save on memory space. On the other hand arduino has lot of libraries so I can google "how to do x in arduino" and get way more results than "how to do x in atmega" for example. But once I find info on how to do it on arduino I can still translate it as needed.