Comments (3)
How can I set values to existing pid with a shellscript or python script?
(not via CMD prompt)?
from elm327-emulator.
Sorry for being late in the answer; my free time is very limited.
put the modified interface to /dev/pts/1
How you do this might not be clear. Notice anyway that if you are using ELM327-emulator as a proxy through its forwarder options, I would not suggest this because that method has been just developed in order to verify and improve the dictionary during the customization phase and not for standard on-line filtering operation.
I don't get what I need to do to modify PID values (or add PIDs) with data from lets say text files containing actual measurement data from external sensors that I added.
I understand that you want to dynamically change the values which are statically predefined in obd_message.py.
I see at least four possibilities.
MODE 1 – using obd_message.py
This method adds a function to obd_message.py to dynamically load a configuration file.
Example.
Create a configuration file (e.g., YAML format):
$ echo -e "---\nINTAKE_PRESSURE: '76'" > /tmp/pid.yaml
Edit obd_message.py and add the following at the top of the file:
import yaml
def load_pid(pid):
with open('/tmp/pid.yaml', 'rb') as f:
conf = yaml.load(f.read(), Loader=yaml.BaseLoader)
return conf[pid]
Take for instance the INTAKE_PRESSURE pid, which returns the following by default.
CMD> test 010B
______Raw command:_______________
'<pos_answer>73</pos_answer>'
______Command output:____________
'41 0B 73 \r\r>'
CMD>
Edit the INTAKE_PRESSURE pid in obd_message.py with the following:
'INTAKE_PRESSURE': {
'Request': '^010B' + ELM_FOOTER,
'Descr': 'Intake Manifold Pressure',
'ResponseFooter': lambda self, cmd, pid, uc_val: PA(load_pid(pid))
},
Now the 'INTAKE_PRESSURE' returns the value defined in /tmp/pid.yaml by reading the file content each time the pid is requested.
MODE 2 – using batch mode
This method loads predefined parameters via batch mode.
Populate a bash configuration file:
echo "INTAKE_PRESSURE='76'" > /tmp/pid.sh
Develop a batch program reading that file periodically (trivial 1-line example):
while true;do . /tmp/pid.sh; echo "emulator.answer['INTAKE_PRESSURE']='<pos_answer>$INTAKE_PRESSURE</pos_answer>'";sleep 1;done | elm -b /tmp/elm.out
Each second the configuration file is read and the INTAKE_PRESSURE answer is dynamically updated.
MODE 3 – using the python interactive mode
This method performs the interactive loading of parameters via Python Interactive mode.
Create a configuration file (e.g., YAML format):
$ echo -e "---\nINTAKE_PRESSURE: '76'" > /tmp/pid.yaml
Create the following Python program:
from elm import Elm
import time
import yaml
def load_pid(pid):
with open('/tmp/pid.yaml', 'rb') as f:
conf = yaml.load(f.read(), Loader=yaml.BaseLoader)
return conf[pid]
with Elm() as session:
# interactive monitoring
pty = session.get_pty()
print(f"Used port: {pty}")
while True:
session.answer['INTAKE_PRESSURE']=(
'<pos_answer>' +
load_pid('INTAKE_PRESSURE') +
'</pos_answer>')
time.sleep(0.5) # example
This program updates the INTAKE_PRESSURE answer evey second by reading its value from the YAML configuration file.
MODE 4 – developing a task
Create a configuration file (e.g., YAML format):
$ echo -e "---\nINTAKE_PRESSURE: '76'" > /tmp/pid.yaml
Edit the INTAKE_PRESSURE pid in obd_message.py by invoking a task named task_intake_pressure with the following:
'INTAKE_PRESSURE': {
'Request': '^010B' + ELM_FOOTER,
'Descr': 'Intake Manifold Pressure',
'Task': 'task_intake_pressure'
},
Create a file named "task_intake_pressure.py" in the plugin directory with the following content:
from elm import Tasks
import yaml
def load_pid(pid):
with open('/tmp/pid.yaml', 'rb') as f:
conf = yaml.load(f.read(), Loader=yaml.BaseLoader)
return conf[pid]
class Task(Tasks):
def run(self, cmd, *_):
return self.PA(load_pid(self.pid)), Tasks.RETURN.TERMINATE, None
Execution example:
$ elm
2022-01-15 12:45:09,259 - root - INFO -
ELM327 OBD-II adapter emulator v3.0.2 started on pseudo-tty port "/dev/pts/1".
Welcome to the ELM327 OBD-II adapter emulator.
ELM327-emulator is running on /dev/pts/1
Type help or ? to list commands.
CMD> test 010B
______Raw command:_______________
'<pos_answer>76</pos_answer>'
______Command output:____________
'41 0B 76 \r\r>'
CMD> os.system("{ echo '---'; echo \"INTAKE_PRESSURE: '74'\";} > /tmp/pid.yaml")
0
CMD> test 010B
______Raw command:_______________
'<pos_answer>74</pos_answer>'
______Command output:____________
'41 0B 74 \r\r>'
CMD>
By far the task method is the most flexible one.
from elm327-emulator.
By far this is the best answer anyone could get. Maybe the best on the internet.
Thank you so much for your time! I will try that.
from elm327-emulator.
Related Issues (20)
- "NO DATA" for PIDs that are clearly in the obd_message.py file HOT 2
- any workarounds for getting it run with virtual COM Ports in Windows? HOT 3
- How to simulate obd2 data? HOT 5
- PIDs supported PID return what is actually support by the emulator
- Wrong RPM being set at certain intervals HOT 1
- How to emulate Bluetooth on MacOS? HOT 2
- Connect Physical device HOT 2
- How to simulate Diagnostic Trouble Code (Mode/Services 03, 07, 0A)? HOT 4
- How To: return remove newline from echo HOT 1
- Connect escaner using Bluetooth HOT 3
- legacy protocol support? HOT 2
- Error at work HOT 2
- PowerBroker2/ELMduino problem with Serial.println
- Problem retrieving codes from python-obd
- Supporting multiple pids for service 01
- How to play back fake speeds/etc? HOT 1
- How to emulate multi frame response ? HOT 1
- Sending/Receiving data from external app (?)
- Limited responses via 0x7DF(Functional request)
- COM3 Problem
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elm327-emulator.