So I’ve downloaded some of the other plugins and looked at the code, and it’s not immediately obvious to me how to do a couple of things. I have a Maxbotix distance sensor that measures the level in my septic tank. I want to create a plugin that can take that data and alert me when it falls outside of thresholds. Every second, the device sends a string (Rxxxx\cr) where “xxxx” is the distance in MM from the sensor.
It’s an RS-232 serial device. However, I have it hooked up to a serial to ethernet converter, and I can connect to it over the network to get the stream of data. Ultimately, I’d like the plugin to be able to:
Connect via serial or IP
Handle multiple devices if I have more than one (Master device, and a button to create child devices with one created by default)
Set high and low alert levels
Convert to other units of measurement
I’m having trouble with the first two items. I can handle the rest, and know how to read data and do stuff with it. Can someone post an example of what I need to do for each of the first two items?
You can take a look at my TCPLighting plugin for sample code regarding the maintenance of child devices. The plugin creates a gateway device on initial installation, and then creates child devices for each bulb as they are detected.
If you install the Virtual Panel plugin it will generate a static JSON and device file. Just fill in the commands, rename the files, put your device ids in and the interface can be done rather quickly. It also generates custom devices on the fly that are controlled by the parent panel manager. It takes the parent child relationship to a whole new level. The caddx plugin is a pretty good example of serial comms. It sounds like your device is similar to motion and door sensors being tripped.
Virtual Panel looks awesome. My data is just a TCP stream though, is there a way to have it connect to a TCP port to collect this data, or can it only do HTTP?
Also, I would need to upgrade to UI7, and I’m afraid it’s going to break everything I have.
You have the whole power of Lua available, including the LuaSocket library, which means you can do just about anything with socket-level communications: TCP, UDP, HTTP, MIME, …
[quote=“signal15, post:1, topic:186443”]So I’ve downloaded some of the other plugins and looked at the code, and it’s not immediately obvious to me how to do a couple of things. I have a Maxbotix distance sensor that measures the level in my septic tank. I want to create a plugin that can take that data and alert me when it falls outside of thresholds. Every second, the device sends a string (Rxxxx\cr) where “xxxx” is the distance in MM from the sensor.
It’s an RS-232 serial device. However, I have it hooked up to a serial to ethernet converter, and I can connect to it over the network to get the stream of data. Ultimately, I’d like the plugin to be able to:
Connect via serial or IP
Handle multiple devices if I have more than one (Master device, and a button to create child devices with one created by default)[/quote]
As others have pointed out, it’s usually a matter of finding a plugin for a device which has roughly similar protocols and modifying it. One of mine, the CurrentCost EnviR, matches your criteria:
[ul][li]Sends a line of text on a periodic basis.[/li]
[li]Can be connected over serial, or you can use an IP-to-Serial gateway.[/li][/ul]
It’s also unfettered with the need for you to send strings from Vera to the serial device, because it sends text autonomously, just like your device. This means that you could copy the Lua startup code and chunks of the Implementation file and get a fair way to where you need to be. In particular, take a peek at L_CurrentCostEnviR1.lua in the initialize() and incoming() functions, and in I_CurrentCostEnviR1.xml, almost all of it. The actual text that the EnviR produces is XML, so you would want to substitute your own code there.
With respect to multiple devices, it depends on whether each sensor has its own RS-232 stream, or if they are multiplexed onto a single RS-232 port with different strings to distinguish different sensors. If the former, you will need to make a new instance of the device for each sensor. If the latter, there are bucketloads of plugins that use the child device interface, among them the EnviR, Philips Hue, or the ones pmnb has already pointed you to.
Best Home Automation shopping experience. Shop at Ezlo!