Skip to content

Commit

Permalink
Can easily use custom log4j2.xml, optionall use purejavacomm, adds tt…
Browse files Browse the repository at this point in the history
…y group
  • Loading branch information
retrodaredevil committed May 21, 2020
1 parent 62dcc6b commit 185092f
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
jacksonVersion = '2.11.0'
retrofitVersion = "2.8.1" // context: https://stackoverflow.com/questions/60915381/retrofit2-maven-project-illegal-reflective-access-warning // https://github.com/square/retrofit/issues/3341
shadowVersion = '5.2.0'
ioLibVersion = '2.0.0'
ioLibVersion = '2.1.0'
}
}
allprojects {
Expand Down
1 change: 1 addition & 0 deletions client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ project.ext.mainClassName = "me.retrodaredevil.solarthing.program.SolarMain"

dependencies {
implementation "com.github.retrodaredevil.io-lib:jSerialComm:$ioLibVersion"
implementation "com.github.retrodaredevil.io-lib:purejavacomm:$ioLibVersion"
implementation 'com.fazecast:jSerialComm:2.6.2' // remove this later
implementation group: 'org.influxdb', name: 'influxdb-java', version: '2.15'
implementation group: 'org.mongodb', name: 'mongodb-driver-sync', version: '3.11.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public AnalyticsManager(boolean isEnabled, File dataDirectory) {
}
if (analyticsData == null) {
analyticsData = new AnalyticsData(UUID.randomUUID());
LOGGER.info(SolarThingConstants.SUMMARY_MARKER, "Generated a new Analytics UUID");
try {
MAPPER.writeValue(file, analyticsData);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.fazecast.jSerialComm.SerialPort;
import me.retrodaredevil.io.IOBundle;
import me.retrodaredevil.io.serial.JSerialIOBundle;
import me.retrodaredevil.io.serial.PureJavaCommIOBundle;
import me.retrodaredevil.io.serial.SerialConfig;
import me.retrodaredevil.io.serial.SerialConfigBuilder;
import me.retrodaredevil.solarthing.annotations.JsonExplicit;
Expand All @@ -29,6 +30,9 @@ public class SerialIOConfig implements IOConfig {
@JsonDeserialize(as = SerialConfigBuilderJackson.class)
private SerialConfig serialConfig;

@JsonProperty("purejavacomm")
private boolean usePureJavaComm = false;

@Override
public IOBundle createIOBundle() throws Exception {
SerialConfig serialConfig = this.serialConfig;
Expand All @@ -42,6 +46,9 @@ public IOBundle createIOBundle() throws Exception {
if(port == null){
throw new NullPointerException("null is not a valid value for the port!");
}
if (usePureJavaComm) {
return PureJavaCommIOBundle.create(port, serialConfig);
}
SerialPort serialPort = JSerialIOBundle.createSerialPortFromName(port);
return new JSerialIOBundle(
serialPort,
Expand Down
52 changes: 52 additions & 0 deletions config_templates/log/remote_log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--NOTE: This is not complete yet-->
<Configuration status="WARN">
<Properties>
<Property name="logPath">logs</Property>
<Property name="LOG_PATTERN">%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n</Property>
<Property name="filePermissions">rw-rw-r--</Property>
</Properties>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<MarkerFilter marker="NO_CONSOLE" onMatch="DENY" onMismatch="NEUTRAL"/>
<PatternLayout pattern="${LOG_PATTERN}"/>
</Console>
<Syslog name="logAll" host="192.168.10.250" port="8514" facility="SYSLOG" protocol="TCP"/>

<RollingFile name="logSummary" fileName="${logPath}/log_summary.log" filePattern="${logPath}/log_summary_%d{yyyy.MM.dd}-%i.log.gz"
filePermissions="${filePermissions}">
<PatternLayout pattern="${LOG_PATTERN}"/>
<MarkerFilter marker="SUMMARY" onMatch="ACCEPT" onMismatch="DENY"/>
<Policies>
<OnStartupTriggeringPolicy />
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
<SizeBasedTriggeringPolicy size="3GB" />
</Policies>
<DefaultRolloverStrategy>
<Delete basePath="${logPath}" maxDepth="1">
<IfFileName glob="log_summary_*.log.gz" />
<IfLastModified age="400d" />
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
</Appenders>
<Loggers>
<Root level="DEBUG" >
<AppenderRef ref="Console" level="DEBUG"/>
</Root>
<Logger name="me.retrodaredevil.solarthing">
<AppenderRef ref="logAll" level="DEBUG"/>
<AppenderRef ref="logInfo" level="INFO"/>
<AppenderRef ref="logSummary" level="DEBUG"/> <!-- We can allow debugs to go through because it will filter for explicit SUMMARY marker -->
</Logger>
<Logger name="org.ektorp" level="INFO">
<AppenderRef ref="logAll"/>
</Logger>
<Logger name="org.apache.http" level="INFO">
<AppenderRef ref="logAll"/>
</Logger>
<Logger name="org.influxdb" level="INFO">
<AppenderRef ref="logAll"/>
</Logger>
</Loggers>
</Configuration>
18 changes: 18 additions & 0 deletions other/docs/log4j.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Log4j
SolarThing uses Log4j2 for logging. (But not the GraphQL program yet, everything else yes)

You can override the default configuration in a few ways:

### `log4j2.xml` in working directory
When executing `run.sh`, it is configured to detect a file called `log4j2.xml` in the working
directory. If it finds it, it will use that for the configuration.
### Environment Variable
```shell script
export LOG4j_log4j2_configurationFile=<path to config>
```
### JVM Argument
```
java -Dlog4j2.configurationFile=<path to config> ...
```

More info: https://stackoverflow.com/questions/778933/log4j-configuration-via-jvm-arguments
2 changes: 1 addition & 1 deletion other/docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Run this to quickly get setup (Linux Only):
# This does NOT configure other random files on your system
curl https://raw.githubusercontent.com/wildmountainfarms/solarthing/master/other/linux/clone_install.sh | sudo bash
# If when testing the program, it helps to have permission to edit files owned by the solarthing group, and you will also want to be allowed to use serial ports
sudo usermod -a -G solarthing,dialout $USER
sudo usermod -a -G solarthing,dialout,tty,video $USER
```
Or if you want to check out how the **simple** installation works: [click here](../linux/clone_install.sh)

Expand Down
26 changes: 26 additions & 0 deletions other/docs/simulate_serial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## Simulate Serial
Here are some commands to help simulate serial

https://stackoverflow.com/questions/52187/virtual-serial-port-for-linux

https://www.onetransistor.eu/2015/12/wine-serial-port-linux.html

```shell script
sudo socat PTY,link=/dev/ttyS10 PTY,link=/dev/ttyS11
```
Connect one end to `/dev/ttyS10` and the other to `/dev/ttyS11`.

Also use this:
```shell script
sudo ./diagslave -m rtu -a 1 -b 9600 -p none /dev/ttyS10
```

If you're doing stuff with wine:
```shell script
cd ~/.wine/dosdevices/
sudo ln -s /dev/ttyS11 com1
```
If you're running Solar Station Monitor using Wine:
```shell script
wine start 'C:\windows\system32\Solar Station Monitor.exe'
```
2 changes: 1 addition & 1 deletion other/docs/updating.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ If you don't have permission to update, it is recommended you run:
```shell script
sudo other/linux/create_user.sh
sudo other/linux/update_perms.sh
sudo usermod -a -G solarthing,dialout $USER
sudo usermod -a -G solarthing,dialout,tty,video $USER
```
This should have already been run if you installed SolarThing using the one line command.
7 changes: 3 additions & 4 deletions other/linux/create_user.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,21 @@ fi

# Add user
if ! id -u solarthing >/dev/null 2>&1; then
useradd -r -g solarthing -G dialout,video solarthing 2>/dev/null # create user with correct groups
useradd -r -g solarthing -G dialout,tty,video solarthing 2>/dev/null # create user with correct groups
if ! id -u solarthing >/dev/null 2>&1; then
echo Unable to create user
exit 1
fi
passwd -l solarthing || (echo Could not lock solarthing passwd; exit 1)
fi
# Add user to groups
usermod -a -G dialout,video solarthing || exit 1 # add groups to user just to make sure they have all needed groups
# dialout is for serial port access
usermod -a -G dialout,tty,video solarthing || exit 1 # add groups to user just to make sure they have all needed groups
# dialout and tty is for serial port access
# video is for 'vcgencmd' command

echo Created \"solarthing\" user and group.
echo You can add a user to the group with \"adduser \<USER NAME HERE\> solarthing\".
echo You need to log out and log back in after adding groups.

#echo The groups you probably need to be a part of are \(These are the Raspberry Pis default:\):
#echo solarthing adm dialout cdrom sudo audio video plugdev games users input netdev gpio i2c spi

3 changes: 3 additions & 0 deletions other/solar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ https://www.wmrc.edu/projects/BARenergy/manuals/outback-manuals/MX60_REV_C.pdf
## Renogy References:
Rover manual: https://www.renogy.com/template/files/Manuals/Rover%20203040%20Manual.pdf

https://renogy.boards.net/thread/565/hp-series-smart-solar-cc
* "administrator", "111111"

Software download: https://www.renogy.com/template/files/Solar%20Station%20Monitor.zip

Modbus protocol: renogy.boards.net/thread/266/rover-modbus
Expand Down
2 changes: 1 addition & 1 deletion program/.scripts/download_if_needed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

BASEDIR=$(dirname "$0")

if ! ls "$BASEDIR/../solarthing.jar" 2>/dev/null 2>&1; then
if ! ls "$BASEDIR/../solarthing.jar" 1>/dev/null 2>&1; then
../download_solarthing.sh || exit 1
fi
5 changes: 5 additions & 0 deletions program/.scripts/solarthing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ echo Using base config = "$BASE_CONFIG"

"$BASEDIR/download_if_needed.sh" || exit 1

if ls log4j2.xml 1>/dev/null 2>&1; then
export LOG4J_log4j2_configurationFile=log4j2.xml
echo Using log4j2.xml file!
fi

if java --add-opens 2>&1 | grep 'requires modules' >/dev/null; then
java --add-opens=java.base/java.lang.invoke=ALL-UNNAMED -jar "$BASEDIR/../solarthing.jar" "$BASE_CONFIG"
else
Expand Down

0 comments on commit 185092f

Please sign in to comment.