Skip to content

Commit

Permalink
support 4-20mA configurator
Browse files Browse the repository at this point in the history
  • Loading branch information
ftylitak committed Sep 8, 2022
1 parent 7126cf4 commit 0afcc42
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 17 deletions.
35 changes: 19 additions & 16 deletions insighioNode/apps/demo_console/demo_sdi12_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,26 +171,29 @@ def current_sense_4_20mA(measurements):
import utime

# sensor 1
gpio_handler.set_pin_value(cfg._UC_IO_CUR_SNS_ON, 1)
gpio_handler.set_pin_value(cfg._UC_IO_SNSR_GND_4_20_SNSR_1_ΟΝ, 1)
if cfg._4_20_SNSR_1_ENABLE:
gpio_handler.set_pin_value(cfg._UC_IO_CUR_SNS_ON, 1)
gpio_handler.set_pin_value(cfg._UC_IO_SNSR_GND_4_20_SNSR_1_ΟΝ, 1)

raw_mV = analog_generic.get_reading(cfg._CUR_SNSR_OUT_1)
current_mA = (raw_mV - 0) / (cfg._SHUNT_OHMS * cfg._INA_GAIN)
print("ANLG SENSOR @ pin {}: {} mV, Current = {} mA".format(cfg._CUR_SNSR_OUT_1, raw_mV, current_mA))
set_value_float(measurements, "curr_port_1", current_mA, SenmlSecondaryUnits.SENML_SEC_UNIT_MILLIAMPERE)
raw_mV = analog_generic.get_reading(cfg._CUR_SNSR_OUT_1)
current_mA = (raw_mV - 0) / (cfg._SHUNT_OHMS * cfg._INA_GAIN)
logging.debug("ANLG SENSOR @ pin {}: {} mV, Current = {} mA".format(cfg._CUR_SNSR_OUT_1, raw_mV, current_mA))
set_value_float(measurements, "curr_port_1", current_mA, SenmlSecondaryUnits.SENML_SEC_UNIT_MILLIAMPERE)

gpio_handler.set_pin_value(cfg._UC_IO_SNSR_GND_4_20_SNSR_1_ΟΝ, 0)
gpio_handler.set_pin_value(cfg._UC_IO_CUR_SNS_ON, 0)
gpio_handler.set_pin_value(cfg._UC_IO_SNSR_GND_4_20_SNSR_1_ΟΝ, 0)
gpio_handler.set_pin_value(cfg._UC_IO_CUR_SNS_ON, 0)

# sensor 2
gpio_handler.set_pin_value(cfg._UC_IO_CUR_SNS_ON, 1)
gpio_handler.set_pin_value(cfg._UC_IO_SNSR_GND_4_20_SNSR_2_ΟΝ, 1)
if cfg._4_20_SNSR_2_ENABLE:
gpio_handler.set_pin_value(cfg._UC_IO_CUR_SNS_ON, 1)
gpio_handler.set_pin_value(cfg._UC_IO_SNSR_GND_4_20_SNSR_2_ΟΝ, 1)

raw_mV = analog_generic.get_reading(cfg._CUR_SNSR_OUT_2)
current_mA = (raw_mV - 0) / (cfg._SHUNT_OHMS * cfg._INA_GAIN)
print("ANLG SENSOR @ pin {}: {} mV, Current = {} mA".format(cfg._CUR_SNSR_OUT_2, raw_mV, current_mA))
set_value_float(measurements, "curr_port_2", current_mA, SenmlSecondaryUnits.SENML_SEC_UNIT_MILLIAMPERE)
raw_mV = analog_generic.get_reading(cfg._CUR_SNSR_OUT_2)
current_mA = (raw_mV - 0) / (cfg._SHUNT_OHMS * cfg._INA_GAIN)
logging.debug("ANLG SENSOR @ pin {}: {} mV, Current = {} mA".format(cfg._CUR_SNSR_OUT_2, raw_mV, current_mA))
set_value_float(measurements, "curr_port_2", current_mA, SenmlSecondaryUnits.SENML_SEC_UNIT_MILLIAMPERE)

gpio_handler.set_pin_value(cfg._UC_IO_SNSR_GND_4_20_SNSR_2_ΟΝ, 0)
gpio_handler.set_pin_value(cfg._UC_IO_CUR_SNS_ON, 0)

gpio_handler.set_pin_value(cfg._UC_IO_SNSR_GND_4_20_SNSR_2_ΟΝ, 0)
gpio_handler.set_pin_value(cfg._UC_IO_CUR_SNS_ON, 0)
utime.sleep_ms(2000)
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
_SDI12_SENSOR_2_ADDRESS = "<meas-sdi-2-address>"

_SDI12_WARM_UP_TIME_MSEC = <meas-sdi-warmup-time>

_4_20_SNSR_1_ENABLE = <meas-4-20-snsr-1-enable>
_4_20_SNSR_2_ENABLE = <meas-4-20-snsr-2-enable>
31 changes: 31 additions & 0 deletions insighioNode/www/step-5-measurements.pyhtml
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,32 @@ def generateOptions(optionsDict):
<div class="col-8 col-sm-12">
<input class="form-input constr-field" type="text" id="input-ins-esp-gen-sdi12-warmup-time"/>
</div>
<div class="form-group">
<div class="col-4 col-sm-12">
<label class="form-label" for="measurements">4-20mA sensor n.1</label>
</div>
<div class="col-8 col-sm-12">
<div class="form-group">
<label class="form-switch">
<input type="checkbox" id="ins-esp-gen-4-20-snsr-1-enable" />
<i class="form-icon"></i>
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-4 col-sm-12">
<label class="form-label" for="measurements">4-20mA sensor n.2</label>
</div>
<div class="col-8 col-sm-12">
<div class="form-group">
<label class="form-switch">
<input type="checkbox" id="ins-esp-gen-4-20-snsr-2-enable" />
<i class="form-icon"></i>
</label>
</div>
</div>
</div>
<br />
<br />
<br />
Expand Down Expand Up @@ -583,6 +609,8 @@ def generateOptions(optionsDict):
Cookies.remove('system-enable-ota')
Cookies.remove('meas-keyvalue')
Cookies.remove('store-meas-if-failed-conn')
Cookies.remove('meas-4-20-snsr-1-enable')
Cookies.remove('meas-4-20-snsr-2-enable')
}

function storeData() {
Expand Down Expand Up @@ -615,6 +643,9 @@ def generateOptions(optionsDict):
Cookies.set('meas-sdi-1-address', address1_elem !== null ? address1_elem.value : "")
Cookies.set('meas-sdi-2-address', address2_elem !== null ? address2_elem.value : "")

Cookies.set('meas-4-20-snsr-1-enable', boolElemToPyStr('ins-esp-gen-4-20-snsr-1-enable'))
Cookies.set('meas-4-20-snsr-2-enable', boolElemToPyStr('ins-esp-gen-4-20-snsr-2-enable'))

Cookies.set('meas-sdi-warmup-time', document.getElementById('input-ins-esp-gen-sdi12-warmup-time').value)
location.href = "step-6-timing.pyhtml"
}
Expand Down
4 changes: 3 additions & 1 deletion insighioNode/www/stored_config_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
"_FORCE_ALWAYS_ON_CONNECTION": "force_always_on_connection",
"_ALWAYS_ON_PERIOD": "always_on_period",
"_MEAS_GPS_NO_FIX_NO_UPLOAD": "meas_gps_no_fix_no_upload",
"_STORE_MEASUREMENT_IF_FAILED_CONNECTION": "store_meas_if_failed_conn"
"_STORE_MEASUREMENT_IF_FAILED_CONNECTION": "store_meas_if_failed_conn",
"_4_20_SNSR_1_ENABLE": "meas-4-20-snsr-1-enable",
"_4_20_SNSR_2_ENABLE": "meas-4-20-snsr-2-enable"
}


Expand Down

0 comments on commit 0afcc42

Please sign in to comment.