Home › Forums › EasyTransfer Library Support Forum › Suggestion: .end command to complement .begin
Tagged: .begin, .end, Easy Transfer, RS485, timeout
- This topic has 7 replies, 3 voices, and was last updated 10 years, 5 months ago by Anonymous.
-
AuthorPosts
-
January 2, 2014 at 8:15 am #3074AnonymousInactive
Hi Bill,
First off, awesome wedding! So glad you guys had a great time and I’m sure the guests were totally wowed by all the time and detail you invested in the event.
I am writing today to inquiry whether you could consider putting an end command into the tool-bag for Easy Transfer. I’ll explain why I think it’s useful and then you can let me know whether I’m doing it all wrong!
In short, I am trying to build a set of connected sensors on modules that share a single RS485 bus (half-duplex) in a master/slave configuration. There are no issues with the command syntax – i.e. the master communicating with the slaves, but the datagrams being sent back ideally would vary by module type (i.e. one module features ten 1-wire sensors and a set of counters, another merely measures power, etc.)
Given that ET is not flexible re: the struct contents changing, I wonder if instead it would be possible to have a complementing “.end” command to the .begin command. This would allow the user to define a multitude of structs and then only associate the relevant one with the serial bus in question at any time.
For example, define one struct each for 3 different data-gathering modules. Then begin and end each ET library as modules are queried for their data and transmit it to the master. That way, one could accommodate different data types from different modules, as long as one keeps track of what type of data to expect from which type of module, and so on.
Make sense? or is there a much better way that you have already thought of? Apologies for being so needy / confused over the years, it really shows that my formal ‘C’ education ended after mere introductory courses.
January 2, 2014 at 1:19 pm #3077AnonymousInactiveApologies, looks like I misunderstood how the system works. Looking through the two-way pot example, it seems as though one can call /declare / start multiple ET programs and then it only matters which one is then used to read the data at any given time. So, a .end command appears superfluous.
January 14, 2014 at 6:20 pm #3085BillMemberYes, end would do you no good as it doesn’t free up RAM or free up the serial port, as it never really demands exclusive control anyway.
But if you are expecting different size structs with different ET objects, you can run into synchronization issues. If your receiver is expecting struct A but gets struct B, it will trash it as bad data.
I’ve been toying with the idea to allow user to ‘address’ structs in ET, giving you the ability to create multiple data sets that could be received, and reporting to the user which data set just came in. But since I haven’t seen many requests for this, it’s on the backburner.
May 5, 2014 at 3:46 pm #3153AnonymousInactiveI’ve been reading through some of the old forum posts, trying to see if I can use EaryTransfer to expand my current project.
I have an Arduino Mega2560 that is capturing 1-wire temperature sensor data, as well as reading the status of my HVAC thermostat control lines (through a relay interface board). All of that gets logged to a MySQL database every 10 seconds. I also have two remote “display” arduinos, which receive the latest data set via EasyTransfer (both are on the same serial bus), and can then display a portion of that data. I’m only using that serial bus in one direction, though (TX from the master to the slaves).
I just added solar panels to my house, so I want to add power production/consumption (by measuring the AC current) to my system.
I found enough information on the current monitoring part to set that up on another Arduino for now. However, I want to be able to bring that data back to the main unit, and store it all together in the same database.
My thought was to make the new Arduino a third slave, and use the same serial bus in the opposite direction to send data from that third slave back to the master. I haven’t figure out, however, how to trigger it.
If I had the ability to send/receive/ignore different structures, I could have the master send out a “send me your data” structure, which the first two slaves would ignore. The third slave, however, would read it and respond back with the “Energy” data set. The third slave would ignore the “HVAC” data set, while the first two slaves would process that data and display it as they do now.May 6, 2014 at 7:12 am #3154AnonymousInactiveI played around with this some last night, and I wanted to add to the post I made yesterday.
I created a test setup with a spare Arduino Mega 2560 as a “master” talking to my EnergyMonitor “slave” over serial (Serial1 on the Mega, SoftwareSerial on the slave) with EasyTransfer.
To start, I created the same data structure from the master as I am using in my production system. I then added an integer variable to it, to indicate the mode (1=request for data, 2=data to display).
I have the master first send the structure with the mode variable set to 1, which triggers the slave to take the energy readings, and send the data back using a second data structure (containing only the two energy usage numbers I need). After the master sends its data, it goes into an ET.receive mode, waiting for the data to be returned. It then does a Serial.print of the variables it received. After that, it sends out the structure with mode=2, and the slave doesn’t do anything (because it has a condition on the value of that mode variable).
What I need to figure out (I didn’t have time to test last night) is what happens if the master sends the first structure (the trigger to send back data), but the slave isn’t running (or locks up of something else that causes the data to never come back)? Is the master going to sit there forever waiting for the data, or does it timeout after a certain period of time, and move on?
If I put in a short delay on the master after sending (long enough for the slave to receive the command, capture the latest data, and send it back), and then do an “if(ET.receiveData())”, will that fail if nothing came back, and then move on (I can put an “else” after it to set the expected values to “null,” so the MySQL insert doesn’t fail).
Would that work? Is there a better way to set a timeout on the ET.receiveData() function?
Thanks.
–Noam
May 6, 2014 at 2:19 pm #3156BillMemberThat would work, you can also read data a certain number of times and then break if nothing came back. like:
int i=0for(; i<10; i++){
if(ET.receiveData()) break;
else delay(100);
}
if(i==10) //put failure code here, since the for loop never broke before i got to 10.
But there’s no right way, it’s whatever way you want to do it. The library itself will never lockup your Arduino because no data is received.
May 7, 2014 at 11:54 am #3160AnonymousInactiveThanks.
I noticed that it doesn’t lock up if it doesn’t receive anything (I had a bad connection on the RX line, and I’m still trying to trace that down). It doesn’t, however, clear the received array if nothing comes in (so it keeps the last received values).
I got around the problem of stale data by adding an additional position to my integer array, and setting it to 0 on the receiving end before telling it to receive data, and setting it to 1 on the transmit end. If it is 1 after running the receiveData() command, then the data is new. Otherwise, it is old data.
If I combine that with the loop you suggested, I should be able to test for new data a few times, and then give up.
But then I ran into a number of other problems last night (*something* is causing the Arduino to hang and/or crash/reboot, and I had to roll back to my stable code and re-try everything.
I have a few more questions:
1. If the sending end transmits before the receiveData() function is run on the recieving end, does that data just stay in the RX buffer until it is read?
2. If “strange” data (non-EasyTransfer) data shows up on the RX line when the receiveData() function runs, what happens? For example, if I send some “regular” serial data out over the serial bus, and the EasyTransfer “slaves” receive it, will they be able to receive the EasyTransfer data that is sent afterward?
Thanks.
–Noam
May 8, 2014 at 8:23 am #3165AnonymousInactiveI decided to continue my problem in the thread I’d started a few months ago for the past issues I had with EasyTransfer and the mysql_connector on my setup.
Here is a link to that thread:
http://www.billporter.info/forum/topic/problems-with-et-ethernet-and-mysql/#post-3164
-
AuthorPosts
- You must be logged in to reply to this topic.