That works ok for in-line code snippets, but it doesn’t really work for multiple lines of code. If you use 3 backticks (```
) in the line before and again in the line after your block of code it works much better
eg
read DATE TIME VOLTAGE AMPS FREQUENCY POWER TOTKWH < /home/pi/DDSD285/meter_data.txt
#
#
/usr/bin/curl -s -m 3 --connect-timeout 2 "http://192.168.0.182/emoncms/input/post?node=TWHGOFFICE&json={POWER:$POWER,TOTKWH:$TOTKWH,VOLTAGE:$VOLTAGE,AMPS:$AMPS}&apikey=5880fexxxxxxxxxxxxxxxxxxxxxxx0493" > /dev/$
would be displayed as
read DATE TIME VOLTAGE AMPS FREQUENCY POWER TOTKWH < /home/pi/DDSD285/meter_data.txt`
#
#
/usr/bin/curl -s -m 3 --connect-timeout 2 "http://192.168.0.182/emoncms/input/post?node=TWHGOFFICE&json={POWER:$POWER,TOTKWH:$TOTKWH,VOLTAGE:$VOLTAGE,AMPS:$AMPS}&apikey=5880xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0493" > /dev/$
Longer code snippets are also reduced with a vertical scroll bar added, here’s the 2 scripts that were linked for downloading (much easier to view within the thread)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import threading, time, subprocess, logging, minimalmodbus
instrument = minimalmodbus.Instrument("/dev/ttyUSB0", 1)
instrument.serial.baudrate = 9600
instrument.serial.parity = minimalmodbus.serial.PARITY_EVEN
instrument.serial.stopbits = 1
instrument.serial.timeout = .5
instrument.debug = True
#print instrument
TOTKWH = round(instrument.read_float((32001-30001),4),4) # Total Energy KWHs
#Address Register Length Parameter Name Access Data Format Units
# (hex) (decimal) (bytes) (string) (R/W) (Float,16bit) A,V,KW,KWh,Hz
# 0x0010 30017 4 Voltage L1 R Float V
# 0x004E 30079 4 Frequency R Float Hz
VOLTAGE = round(instrument.read_float((30017-30001),4),4)
FREQUENCY = round(instrument.read_float((30079-30001),4),4)
#Address Register Length Parameter Name Access Data Format Units
# (hex) (decimal) (bytes) (string) (R/W) (Float,16bit) A,V,KW,KWh,Hz
# 0x0058 30089 4 Current Total R Float A
AMPS = round(instrument.read_float((30089-30001),4),4)
#Address Register Length Parameter Name Access Data Format Units
# (hex) (decimal) (bytes) (string) (R/W) (Float,16bit) A,V,KW,KWh,Hz
# 0x0090 30145 4 Power L1 R Float KW
POWER = (round(instrument.read_float((30145-30001),4),4)*1000)
#BAUDRATE = instrument.read_register((31318-30001),0,4)
# SETBAUD = instrument.write_register((31318-30001),38400,0,6)
#print BAUDRATE
print('Volts Amps Frequency Hz Power Load Watts Total KWHs\n{} {} {} {} {} \n'.format(VOLTA$
#print time.strftime('%Y%m%d %X ')
file = open('/home/pi/DDSD285/meter_data.txt', 'w+')
file.write(time.strftime('%Y%m%d %X '))
file.write('{} {} {} {} {}\n'.format(VOLTAGE,AMPS,FREQUENCY,POWER,TOTKWH))
file.close()
subprocess.call('/home/pi/DDSD285/send-to-emoncms.sh') # call the bash file to transmit the data
exit()
#!/bin/bash
#
# I gave the variables (DATE TIME GENW VOLT etc) the same names I used in the Python script.
# It made things easier to keep track of. They can be given any name you like.
#
# Generate a "here doc" that takes its data from the meter_data.txt file written by the Python script.
read DATE TIME VOLTAGE AMPS FREQUENCY POWER TOTKWH < /home/pi/DDSD285/meter_data.txt
#
#
#/usr/bin/curl -s -m 3 --connect-timeout 2 "http://192.168.0.182/emoncms/input/post?node=TWHGOFFICE&csv=$POWER,$TOTKWH&apikey=588xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0493" > /dev/null
/usr/bin/curl -s -m 3 --connect-timeout 2 "http://192.168.0.182/emoncms/input/post?node=TWHGOFFICE&json={POWER:$POWER,TOTKWH:$TOTKWH,VOLTAGE:$VOLTAGE,AMPS:$AMPS}&apikey=5880xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0493" > /dev/$
#
# -s is the curl "silent" switch.
# -m sets the maximun amount of time (in seconds) curl is allowed for the entire send transaction.
# set the node number to the node that has the data you want to transmit.
#
# Variables
# GENW = GENerated power in Watts, from my pv system
# HTOT = House TOTal. total house load, in Watts.
# VOLT = self explanatory.
# CONS = present CONSumption in Watts.
# TEC = Total Energy Consumed in KWh.
# IMPA = IMPorted energy, Leg A, in KWh.
# IMPB = IMPorted energy, Leg B, in KWh.
# EXPA = EXPorted energy, Leg A, in KWh.
# EXPB = EXPorted energy, Leg B, in KWh.
# NETA = NET energy, Leg A.
# NETB = NET energy, Leg B.
# NETC = pv production in KWh.
It’s much easier to discuss code without needing to download it, Just plant the code between 2 sets of 3 back ticks eg
```
chunk of code
```
Edit - munged API key. BT - Moderator.