A Forum run by Enthusiasts of MidNite Solar

The Open Source software/hardware corner => Arduino => Topic started by: dgd on November 11, 2015, 02:47:39 PM

Title: Ethernet Modbus port for KID
Post by: dgd on November 11, 2015, 02:47:39 PM
Have started new thread for this little project,  as its separate from the simple webserver for the KID.

The webserver extracts serial port data from KID and using AJAX serves it to a a connecting web client using various html5
pages for display. This happens in almost real time with refreshing just under a second for  web displayed data.

KAP - Kid Access Port  8)
This KAP project gets serial data every fraction of a second from the KID and stores it in series of memory locations that will be mapped to modbus register addresses so that an ethernet connecting modbus master can see this as a slave device and retreive the requested register values.

It appears that almost everything necessary for this, especially all the modbus protocol/timing management, already exists in the SimpleModbusSlave library for the Arduino.
The storing of serial data into a memory array and then mapping modbus register addresses to array index entries also looks fairly striaghforward although it may be necessary to link an address parser routine to the modbus lib to ensure a valid register address or range is specified.
This IMO would be preferable to lengthy (relative) delays while the slave times out due to invalid register requests.

I'm thinking of using identical register addresses as the Classic (eg 4114 for battery voltage etc..) although the extent of this will be limited by the serial data types that the KID provides.

The arduino processor will also store, eeprom, static info about the KID, such as version, serial number although these would probably need to be done in the c++ sketch code and map these into the relevant modbus registers 4101+
Including an RTC with the arduino is also straighforward. so date and time stamping of data is possible.
Because of limited memory I have not yet considered any type of log file but the possibility is there.

Anyone any design contributions, ideas, thoughts or comments on this?

dgd
Title: Re: Ethernet Modbus port for KID
Post by: dgd on November 11, 2015, 05:00:34 PM
This is the hardware I want to use in this project, all nice and tiny to fit underneath the KID in the support bracket void.
The only external connector is the ethernet port, a short rj11 cable goes to the Kid's serial port.
The max232 tiny pcb is soldered to end of cable. The arduino is a small footprint version of the Nano without the integral USB port. Instead it has ttl serial port connections and for programming uses an external usb to ttl board. When connected to the Kid this is replaced by the max232 (rs232 to ttl) serial converter.
Shown in centre without interface pins installed yet.
The RTC and eeprom card is shown, flat battery receptacle underneath, also has connector pins installed
Also a tiny 12v fan is shown and an MN hole cover to give idea of size of everything.

Not shown is the Wiznet 550io tiny ethernet board as the one  I have is in use so waiting on more to arrive
Here is info on interfacing it to Nano
http://www.instructables.com/id/Arduino-Nano-with-WIZ550io-Easy-Internet/ (http://www.instructables.com/id/Arduino-Nano-with-WIZ550io-Easy-Internet/)

Hardware all up cost about USD25
The plan is to power all of this from the KID but I need to investigate if any 5v power is avaiable from a TP or whatever otherwise its a small its a small power unit connecting to battery terminals.

dgd
Title: Re: Ethernet Modbus port for KID
Post by: Westbranch on November 11, 2015, 05:14:06 PM
DGD said:
Not shown is the Wiznet 550io tiny ethernet board as the one  I have is in use so waiting on more to arrive

sure looks like the unit here   http://www.shopwiznet.com/wiz550io

The plan is to power all of this from the KID but I need to investigate if any 5v power is available from a TP or whatever otherwise its a small its a small power unit connecting to battery terminals.

Wouldn't the load circuit power supply give you 12 V that you could step down from?
Title: Re: Ethernet Modbus port for KID
Post by: Graham on November 11, 2015, 05:24:44 PM
I'm doing the same using a raspberry pi using the https://github.com/stephane/libmodbus (https://github.com/stephane/libmodbus) c++ library.
I initialized the modbus data to match a classic so I could access it using the local or my android app.
Still very much a work in progress since I'm simulating a kid on a pc. I wasn't able to make sense of the sample kid data found on another post in this forum.
Let me know if I can help with the code...


Graham.
Title: Re: Ethernet Modbus port for KID
Post by: dgd on November 11, 2015, 05:58:44 PM
Graham,

I wrote a Classic modbus simulator for an UNO to connect to my DUE web server system so basically all I had to do was sort out some modbus register map addressing and get that serial port interface to the KID working.
The Arduino SimpleModbus libs had it all, at least all I needed
It sure would be nice to have some clearer documentation about getting data from the KID as it was interesting trying to understand Mario's explanation {ok going out on a limb here but I got the distinct impression English is not Mario's first language  :) }
Maybe someone else at MN could assist with a nicely documented description ?

Also looks like the MN localApp will talk but its doubtful the MyMN system would be interested as I remembered it has
some dubious encryption in its comms.
Anyway good to see your progress, I will get back to you later about C code

dgd
Title: Re: Ethernet Modbus port for KID
Post by: dgd on November 11, 2015, 06:05:04 PM
Quote from: Westbranch on November 11, 2015, 05:14:06 PM
Wouldn't the load circuit power supply give you 12 V that you could step down from?

Yes, it probably would but being a lazy type I want to find a 5v supply from the KID as its already generating this for its ttl logic devices (I don't think its 3.3v).
I sort of have this plan, maybe unrealistic, to have this little cpu and bits closely integrated into the KID mounting rather than an external box.

dgd
Title: Re: Ethernet Modbus port for KID
Post by: dgd on November 11, 2015, 08:48:58 PM
Just been thinking about this concept and widening its application (with the assistance of some single malt nectar).
The idea of an access port for the KID could easily be widened  to be an ethernet modbus port for the Classic and especially the Classic SL.
With the ongoing strife concerning the Classic ethernet port reliabiity AND its broken (IMHO) stack that permits only one tcp connection at any time PLUS the horrors (again IMHO) of an encrypted data link from the Classic owners LAN to some anonymous remote server , I'm coming to the conclusion that a Classic access port that would allow multiple tcp connections to a modbus stack in the access port device is the way to go.

This would allow the Classics ethernet port to be abandoned and serial data from Classic to port device where a suitable modbus stack is maintained.

Perhaps the main issue here might be the maximum serial port throughput although some tuning of serial ring buffer sizes can significantly improve throughput timing.
Maybe the Classic's usb port could be useful here for higher throughput although I'm not sure if its version 1 or 2  as its unlikely to be version 3. Even vers 1 with 12Mbit throughput would be nice if the Classic's cpu could handle it.

Now this would be the more worthwhile project IMO and the Cubie would fit quite nicely.  :o

dgd
Title: Re: Ethernet Modbus port for KID
Post by: Graham on November 12, 2015, 01:29:55 PM
Quote from: dgd on November 11, 2015, 05:00:34 PM
This is the hardware I want to use in this project, all nice and tiny to fit underneath the KID in the support bracket void.
The only external connector is the ethernet port, a short rj11 cable goes to the Kid's serial port.
The max232 tiny pcb is soldered to end of cable. The arduino is a small footprint version of the Nano without the integral USB port. Instead it has ttl serial port connections and for programming uses an external usb to ttl board. When connected to the Kid this is replaced by the max232 (rs232 to ttl) serial converter.
Shown in centre without interface pins installed yet.
The RTC and eeprom card is shown, flat battery receptacle underneath, also has connector pins installed
Also a tiny 12v fan is shown and an MN hole cover to give idea of size of everything.

Not shown is the Wiznet 550io tiny ethernet board as the one  I have is in use so waiting on more to arrive
Here is info on interfacing it to Nano
http://www.instructables.com/id/Arduino-Nano-with-WIZ550io-Easy-Internet/ (http://www.instructables.com/id/Arduino-Nano-with-WIZ550io-Easy-Internet/)

Hardware all up cost about USD25
The plan is to power all of this from the KID but I need to investigate if any 5v power is avaiable from a TP or whatever otherwise its a small its a small power unit connecting to battery terminals.

dgd

Another interesting hardware option is the NodeMCU http://nodemcu.com/index_en.html#fr_54747661d775ef1a3600009e (http://nodemcu.com/index_en.html#fr_54747661d775ef1a3600009e).
It's based on the esp8266 so it has built in wifi that can be both a station and an endpoint.
If the kid is in a motor home or boat, you wouldn't need a router, just wifi connect directly
It's only $2 http://www.ebay.ca/itm/171907430053?_trksid=p2060353.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT (http://www.ebay.ca/itm/171907430053?_trksid=p2060353.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT)
or $12 for the dev kit http://www.seeedstudio.com/depot/NodeMCU-v2-Lua-based-ESP8266-development-kit-p-2415.html (http://www.seeedstudio.com/depot/NodeMCU-v2-Lua-based-ESP8266-development-kit-p-2415.html)
all you need to add is a 3v regulator and an rs232 interface.


Graham.
Title: Re: Ethernet Modbus port for KID
Post by: dgd on November 12, 2015, 06:29:15 PM
I see the ESP8266 is now supported in a recent release of the Arduino IDE. I have ordered a few of them to play with.
Low cost serial to Wifi would fit nicely into the sort of adaptor port I'm thinking of.

The DUE web server I use with my two Classics (and soon MX60/) uses a Dragino WIFI shield to connect to my WIFI Lan.
A second DUE server dealing with a MS MPPT30 and KID also has a WIFI shield, this time a CC3300, still doing some development with this one but as its a very low cost chinese shield its worth the effort.

dgd
Title: Re: Ethernet Modbus port for KID
Post by: Graham on February 28, 2016, 11:01:00 AM
Quote from: dgd on November 12, 2015, 06:29:15 PM
I see the ESP8266 is now supported in a recent release of the Arduino IDE. I have ordered a few of them to play with.
Low cost serial to Wifi would fit nicely into the sort of adaptor port I'm thinking of.

The DUE web server I use with my two Classics (and soon MX60/) uses a Dragino WIFI shield to connect to my WIFI Lan.
A second DUE server dealing with a MS MPPT30 and KID also has a WIFI shield, this time a CC3300, still doing some development with this one but as its a very low cost chinese shield its worth the effort.

dgd

I've been playing with the ESP12e for a few weekends, I have a couple of projects on my github page.
The ModbusAdapter project uses a esp12e along with a rs232/ttl adapter to convert a modbus RTU slave to a Modbus TCP slave over wifi. I tested it using the classics serial port and was able to connect using the local app over tcp/wifi.
It currently implements Holding Register read (0x03).
The implementation in TCPSlave.h/cpp could be replaced with the code that communicates with the kid over serial to add modbus TCP/Wifi access to the kid.


https://github.com/graham22/ModbusAdapter (https://github.com/graham22/ModbusAdapter)

other NodeMCU/ESP8266 project that uses webSockets to broadcast wind speed to a web page:
https://github.com/graham22/Anemometer (https://github.com/graham22/Anemometer)


Graham.
Title: Re: Ethernet Modbus port for KID
Post by: dgd on February 28, 2016, 02:44:40 PM
Thanks for the info Graham.
I dont see any issues with the KID adaptor, its just a matter of waiting on the next FW release to get some more useful data from the KID serial port. I have tested using the modbusSlave lib and making data available is not too difficult. Eventually I can see the KID talking to the local app and with some little effort to MyMN.

dgd
Title: Re: Ethernet Modbus port for KID
Post by: jeremy450 on May 03, 2017, 01:03:50 PM
hi dgd

just wondering how you been going with the Ethernet Modbus port for KID for the arduino.

regards
Jeremy
Title: Re: Ethernet Modbus port for KID
Post by: ClassicCrazy on May 03, 2017, 03:17:18 PM
Quote from: Graham on February 28, 2016, 11:01:00 AM
Quote from: dgd on November 12, 2015, 06:29:15 PM
I see the ESP8266 is now supported in a recent release of the Arduino IDE. I have ordered a few of them to play with.
Low cost serial to Wifi would fit nicely into the sort of adaptor port I'm thinking of.

The DUE web server I use with my two Classics (and soon MX60/) uses a Dragino WIFI shield to connect to my WIFI Lan.
A second DUE server dealing with a MS MPPT30 and KID also has a WIFI shield, this time a CC3300, still doing some development with this one but as its a very low cost chinese shield its worth the effort.

dgd

I've been playing with the ESP12e for a few weekends, I have a couple of projects on my github page.
The ModbusAdapter project uses a esp12e along with a rs232/ttl adapter to convert a modbus RTU slave to a Modbus TCP slave over wifi. I tested it using the classics serial port and was able to connect using the local app over tcp/wifi.
It currently implements Holding Register read (0x03).
The implementation in TCPSlave.h/cpp could be replaced with the code that communicates with the kid over serial to add modbus TCP/Wifi access to the kid.


https://github.com/graham22/ModbusAdapter (https://github.com/graham22/ModbusAdapter)

other NodeMCU/ESP8266 project that uses webSockets to broadcast wind speed to a web page:
https://github.com/graham22/Anemometer (https://github.com/graham22/Anemometer)


Graham.

Graham - guess I missed this post last year.
What do you use to compile and load your code into the ESP8266 ? I am a bit new to this - can I just use the .ino file you have listed and use the Arduino IDE ? 

I looked briefly at your wind speed project too. Adafruit is out of those anemometers . Most anemometers I have seen use magnet reed switch to count like this one . https://www.argentdata.com/catalog/product_info.php?products_id=175
The Adafruit  one sends a voltage.

Thanks for sharing your code and projects.
I will give them a try sometime.

For the ESP 's I have been using EspEasy - have you played around with that ?
This is the new beta Mega software they have been working on
https://www.letscontrolit.com/forum/viewtopic.php?f=18&t=2257&sid=f70442693672093478ae37861eb89f3d

Larry
Title: Re: Ethernet Modbus port for KID
Post by: Graham on May 06, 2017, 08:16:44 AM
Quote from: ClassicCrazy on May 03, 2017, 03:17:18 PM


Graham - guess I missed this post last year.
What do you use to compile and load your code into the ESP8266 ? I am a bit new to this - can I just use the .ino file you have listed and use the Arduino IDE ? 

I looked briefly at your wind speed project too. Adafruit is out of those anemometers . Most anemometers I have seen use magnet reed switch to count like this one . https://www.argentdata.com/catalog/product_info.php?products_id=175
The Adafruit  one sends a voltage.

Thanks for sharing your code and projects.
I will give them a try sometime.

Larry

Hi Larry,

You can use the arduino IDE if you add the https://github.com/esp8266/Arduino (https://github.com/esp8266/Arduino) using the board manager. I use Visual Studio with the Visual Micro extension, it allows me to code in C++ to create libraries etc.  http://www.visualmicro.com/page/Arduino-Visual-Studio-Downloads.aspx (http://www.visualmicro.com/page/Arduino-Visual-Studio-Downloads.aspx).

Quote from: ClassicCrazy on May 03, 2017, 03:17:18 PM

For the ESP 's I have been using EspEasy - have you played around with that ?
This is the new beta Mega software they have been working on
https://www.letscontrolit.com/forum/viewtopic.php?f=18&t=2257&sid=f70442693672093478ae37861eb89f3d

Larry

Interesting project, are you going to have an android app as the UI   :)


Graham.
Title: Re: Ethernet Modbus port for KID
Post by: ClassicCrazy on May 07, 2017, 12:53:23 AM
Graham  - I do have the esp boards set up in Arduino - just could never figure out how to add different sensor plug ins and get them to compile in the EspEasy and show up  on their list of sensors when I tried it. I am a novice at this kind of thing .  I have SHT30 temperature humidity sensors and someone wrote plug in for it but never got it compiled. But someone else wrote an ESP webpage for SHT30 sensor the continuously updates and that works great.
https://www.youtube.com/watch?v=xs2Y30LhO1A&t=6s

So I just use EspEasy as is - load it into Esp Wemos Pro mini using the FlashESP8266.exe  program that is included in the EspEasy downloads with their bin files.  Then I can just go to the built in ESPEasy webpage via whatever network address the device takes on the network.

Have to wait for a pro like you to make it work better !

Would be a great add on to be able to make a plug in wifi via ESP to Classic especially if it pulls the power off of the Classic . 

Larry
Title: Re: Ethernet Modbus port for KID
Post by: Damon on February 21, 2019, 08:22:42 AM
Hi dgd et. al., I'm wondering how your KID access projects have gone and whether you have any learnings to share with someone just starting theirs?

I have an Arduino Yun (v1) as a submeter in my house, and am working on a second project using a MKR GSM 1400 board as a remote boat monitor.

Data from the KID is on my "nice to have" list since I have mostly figured out how to get similar information from the Victron BMV 600 battery monitor. The main purpose of this project is to let me know if the batteries are low or there is water where there shouldn't be (not that I have returned to the boat with dead batteries or a flood ever before :-\ ). The MKR checks sensors and sends data to an IoT website every so often, and I want it to wake and send immediate notification under certain conditions. I think those criteria will all be from the BMV or the water sensors, but maybe something from the KID or it may be useful to log what's going on there? Or I could compare the KID and BMV readings (e.g. battery voltage) as QA. One thing I do want to know from the KID is if it's on. I think this is the best trigger for my monitor to know it's summer, the solar is up and running, so we are most likely but not certainly in the water, and we have plenty of incoming power. When the PV is off, we are probably on land, with the cover on, so no dispatching anything through relays, and less frequent updates.

I have spare Arduinos kicking around and could assign one to augment the KID rather than tying the KID directly into my boat monitor.

Additional context:
The boat is wind powered with solar backup. Sails are the first choice, but the auxiliary is a 5.5 kW (continuous) electric motor at 48V drawing from a 3.3 kWh bank of AGMs, which are charged by a 390 W of PV feeding through a MidNite KID. (The motor seemed quite powerful and this system quite capable when I installed it in 2012, but today....yay for what's happening!)