Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
EasyG0ing1 committed Jan 9, 2025
0 parents commit 1c8fc20
Show file tree
Hide file tree
Showing 6 changed files with 572 additions and 0 deletions.
92 changes: 92 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# UDPLog
This project is a simple UDP server host that can run multiple instances of a UDP server on different ports. When data is sent to it, it writes the data to a log file.

You can configure it using a simple `settings.ini` file.

### Intent
The original purpose of this project was to provide a way for microcontrollers such as the Arduino line or the `Raspberry Pi Pico W` etc. to be able to send data to a computer for ongoing data logging. Doing it over the network is MUCH EASIER than trying to do it via bluetooth over serial.

The program will work for anything that can send data via UDP to an IP address or network host, it is not limited to microcontroller projects.

## Installation
Look in the releases section and download the zip file for your operating system, then unzip it. It has been compiled on MacOS, Windows and Ubuntu Linux. They are native binaries and do not require the Java virtual machine to run. When you download the executable, you run it and after first launch, it will create a file in the folder it was launched from called `settings.ini`.

## Usage
Open the settings file and change the options to suit your needs. The format of the settings file is:

```
[Server1]
port=4444
bufferSize=512
logFile=/Users/user/logs/logFile1.txt
[Server2]
port=4445
bufferSize=512
logFile=/Users/user/logs/logFile2.txt
```

Here is the breakdown

- Section Heading
- The section headings must be enclosed in brackets and the first word must be `Server`. Each section will create a new UDP server instance, so you can have as many as you like. You're only limited by the amount of RAM you have in your computer and each instance doesn't take much ram at all (maybe a hundred bytes or less).

- ***port***
- This is the UDP port number that you need to send your data to (1 - 65535) see [this link](https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers) for port numbers you should not use.
- ***bufferSize***
- This is the size of the UDP packet you desire to send. In Arduino environments, make this number larger than the buffer size you use to build your UDP packet. If that size is unknown then simply set it to be larger than the largest size your project might send. The data frame in a UDP packet can only be 65,535 bytes (64k), but there is overhead in those packets so your size should be smaller than that. Common practice is to not exceed 1,500 for your packet size because of fragmentation potential etc. But on a local network, you can safely go much larger than that since you most likely won't be traversing multiple routers processing heavy amounts of traffic. You don't need to be precise here ... going with a size that is larger than you anticipate is a good idea (so lets say you wont ever send a packet larger than 500 bytes, set this value to 1,000 and you'll be fine)
- ***logFile***
- This is the FULL PATH to the log file that you want that specific server instance to write the data to. (A Windows path would need to be in standard Windows path format - `C:\Users\user\logs\logFile.txt` for example)

### Program Arguments
```aiignore
UDPLog test
UDPLog version
```

Passing in the word `test` will give you feedback as the program runs which lets you perform data send tests and the program will let you know if your data was received etc.

## Example Arduino Code
This is how a typical Arduino sketch might look like that would use this program:
```C++
#include <WiFi.h>
#include <WiFiUdp.h>

WiFiUDP udpSend;

const auto ssid = "ssid";
const auto password = "ssidPassword";
const IPAddress logIPAddress(192,168,1,15); // IP address to send data to
constexpr uint32_t logPort = 60379; // UDP port to send data on

void sendUDP(const String &msg, const int udpPort = logPort) {
if (WiFi.status() == WL_CONNECTED) {
int len = msg.length();
char buffer[len + 1];
snprintf(buffer, sizeof(buffer), "%s", msg.c_str());
udpSend.beginPacket(logIPAddress, udpPort);
udpSend.write(buffer);
udpSend.endPacket();
}
}

void setup() {
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
}

void loop() {
if(logData) {
sendUDP(myLogData, logPort);
}
}
```
## Service / Daemon
You can use the program as a Windows service or a linux daemon, but you'll have to Google how to do that if you're interested in it.
### Assistance
If you have any questions, comments or problems, simply create an Issue in this repo and I'll reply as soon as I see it.
# Release Notes
- 1.0.0 - Initial release
163 changes: 163 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.simtechdata</groupId>
<artifactId>UDPLog</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>

<name>UDPLog</name>
<description>Creates Server threads that listen for data on UDP ports then logs data into log files</description>

<properties>
<maven.compiler.source>22</maven.compiler.source>
<maven.compiler.target>22</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<versions-maven-plugin>2.18.0</versions-maven-plugin>
<maven-enforcer-plugin>3.5.0</maven-enforcer-plugin>
<maven-assembly-plugin>3.7.1</maven-assembly-plugin>
<native-maven-plugin>0.10.4</native-maven-plugin>
<mainClass>com.simtechdata.App</mainClass>
<system-linker-arg/>
<system-native-image-arg/>
<compatibility-arg/>
<package.type/>
</properties>

<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.18.0</version>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>version.properties</include>
</includes>
</resource>
</resources>
<plugins>
<!-- Maven Versions -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>${versions-maven-plugin}</version>
<executions>
<execution>
<goals>
<goal>display-dependency-updates</goal>
<goal>display-plugin-updates</goal>
<goal>property-updates-report</goal>
<goal>dependency-updates-report</goal>
<goal>plugin-updates-report</goal>
<goal>update-properties</goal>
<goal>use-latest-versions</goal>
</goals>
</execution>
</executions>
</plugin>
<!--Maven Enforcer Plugin-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>${maven-enforcer-plugin}</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>4.0.0-beta-3</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<!-- Maven Assembly Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>${maven-assembly-plugin}</version>
<configuration>
<archive>
<manifest>
<mainClass>${mainClass}</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>${name}</finalName>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>maven_central</id>
<name>Maven Central</name>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
</repositories>
<profiles>
<!--native profile-->
<profile>
<id>native</id>
<build>
<plugins>
<!-- GraalVM Native Maven Plugin -->
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>${native-maven-plugin}</version>
<extensions>true</extensions>
<executions>
<execution>
<id>build-native</id>
</execution>
</executions>
<configuration>
<target>${java.version}</target>
<imageName>${project.name}</imageName>
<mainClass>${mainClass}</mainClass>
<verbose>true</verbose>
<fallback>false</fallback>
<buildArgs>
<arg>-Djava.awt.headless=true</arg>
<arg>--no-fallback</arg>
<arg>--verbose</arg>
<arg>--enable-preview</arg>
<arg>--enable-http</arg>
<arg>--enable-https</arg>
<arg>--initialize-at-build-time=org.sqlite.util.ProcessRunner</arg>
<arg>-H:+UnlockExperimentalVMOptions</arg>
<arg>-H:+ReportExceptionStackTraces</arg>
<arg>-H:Name=${project.name}</arg>
</buildArgs>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Loading

0 comments on commit 1c8fc20

Please sign in to comment.