I have an arduino which is reading a digital signal for a machine and using some logic to write to an API via http post/wifi. This is working fine most of the time but once in a while I get some data points which do not make sense. I believe this is related to some timming issues on the API which blocks the loop.
I would like to simulate the machine signal using some comparable time series on the PC and thought of using a second arduino, connected to the first (digit out to digital in) and maybe pass the signal from the PC via serial connection. I really dont wan't to change the code in the "tested" arduino so I'm just looking for an external solution to better simulate the real machine. Lets Day the 2nd Arduino would act as a virtual machine with the sensor, controlled by a PC.
Can you help me understand if this is a way to go, and maybe some suggestion I should use on the PC to facilitate the task of sending the time series in the correct timming to the 2nd Arduino?
I would really appreciate your thoughts/help on this.
Show us the schematics and code from Your project.
Hunting the theory You have today and maybe another tomorrow sounds no good. The target is a working setup, isn't it?
Do you use a ESP32 with the newest versions of the software ?
If you use a Arduino Mega with a Ethernet Shield, then there might be timing issues or TCP protocol problems or open sockets that build up.
The cause of the problem is the wrong data points. That should not be possible. A timing issue should not cause wrong data. Can you tell more about that ? Perhaps you are looking at the HTTP API while the sensor has a loose wire.
Thank you for your answer.
I should not have used the term wrong "data points" . The problem is I'm checking a certain port looking if the machine is "in cycle" or "stopped". When the I detect a cycle change I use http.post to send this information to the server via an API. I suspect a timming issue on the http.post (maybe it is getting hanged or is waiting - the loop cycle waits) because I have periods where the number of cycles I have for the window of time it takes is slower than the slowest possible speed of the physical machine.
This is not a consistent problem. It only happens every few days on different machines (no visible pattern). I'm logging every connection error (lost wifi signal) but the periods do not match.
I use an ESP32 with a NodeMCU Module (ESP8266).
My original question was just a request for help on finding a way to "simulate" the original machine so I can try and replicate the problem.
Using a second Arduino sounds like a good idea. Especially if you arrange it so that you can repeat the cycle in case you do have to modify the primary Arduino's code, you can prove to yourself that the fix was effective.
It is an approach, a better one would be to record the original machine signal to a log file on SD and then replay the captured signal. This affords you direct analysis of the input once an error has surfaced. Instead of SD, you could use a PC file too. It is your choice how you add a timestamp to an SD, on the PC you could use an On/Off tone to represent logic and record directly over several days, thus avoiding timestamps except for the start time-date; that is the PC file is in start-time referenced.
I think it might be a good idea to simulate the input as well. In addition, if you post your code with a good description of what is expected and what is happening we may be able to spot an issue with the code or come up with a solution. Of course that is up to you but we are glad to help out there too.
Actually I think I will go ahead and mix your suggestions. I will use a 2nd arduido to read the sensor from the machine in paralell with the first arduino and record the data without having the suspected timming issues from the http calls. That will allow me to discard or confirm the signal from the machine is correct. If it is I can then use that saved data to build my time series as a realistic one to simulate the machine on the same 2nd arduino and connect it to the first as a "virtual machine".
I will post the code for this 2 trials as soon as I get it done.