Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FTP Upload binding #3137

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1aa36ce
Initial commit for NetworkCameraMotionDetectionBinding
paulianttila Feb 13, 2017
1617930
Added README.md
paulianttila Feb 14, 2017
e166c93
Added about.html
paulianttila Feb 14, 2017
33be6fc
Removed language property file
paulianttila Feb 14, 2017
24961c8
Renamed thing type from NetworkCamera to networkcamera
paulianttila Feb 14, 2017
ee16732
Updated Ftp server and mina libraries
paulianttila Feb 14, 2017
5acb7e3
Fixed logging
paulianttila Feb 14, 2017
7c6d4c3
Added FTP server logging instructions
paulianttila Feb 14, 2017
fa83406
Few minor fixes
paulianttila Oct 5, 2017
7bf4303
Minor fixes
paulianttila Oct 5, 2017
4c0f0ec
Minor fixes
paulianttila Oct 5, 2017
7841816
Minor fixes
paulianttila Oct 5, 2017
6721920
Fixed readme
paulianttila Oct 19, 2017
070a22c
Improvements
paulianttila Jan 17, 2018
6567b5e
Improvements
paulianttila Jan 17, 2018
5d3e1a7
Renamed binding to networkcamera
paulianttila Jan 18, 2018
14f604f
Updated headers
paulianttila Jan 18, 2018
9c53c61
Added missing new line
paulianttila Jan 18, 2018
b8a93e1
Reformatted xml
paulianttila Jan 18, 2018
999d9fd
Make Martin happy
paulianttila Jan 18, 2018
8420875
Renamed directory
paulianttila Jan 20, 2018
e25f6c4
Code review and other fixes
paulianttila Apr 23, 2018
a52ba91
Use DS annotations
paulianttila Apr 23, 2018
f35024f
Removed motion channel
paulianttila Apr 23, 2018
41626d2
Divided FTP server private classes to own classes
paulianttila Apr 23, 2018
506ebb1
More fixes
paulianttila Apr 24, 2018
c932bdd
Modified callback function execution
paulianttila Apr 24, 2018
98a1cb8
Added binding to build
paulianttila Apr 25, 2018
8bd3452
Throw exception if FTP server start fails
paulianttila Apr 25, 2018
e63481e
Improved thing status handling when FTP server startup fails
paulianttila Apr 26, 2018
5b9568c
Added support for custom channels
paulianttila Apr 28, 2018
28f384d
Renamed binding to ftpupload
paulianttila Apr 28, 2018
aa7a6e6
Fixed thing type
paulianttila Apr 28, 2018
4e534f1
Code review fixes
paulianttila May 2, 2018
3db01a0
Typo fixes
paulianttila May 2, 2018
98d6594
Code review fixes
paulianttila May 7, 2018
8641dd8
Added binding to features
paulianttila May 7, 2018
9e3ce04
Spaces to tabs
paulianttila May 8, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions addons/binding/org.openhab.binding.ftpupload/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="lib" path="lib/ftplet-api-1.1.0.jar"/>
<classpathentry kind="lib" path="lib/ftpserver-core-1.1.0.jar"/>
<classpathentry kind="lib" path="lib/mina-core-2.0.16.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
33 changes: 33 additions & 0 deletions addons/binding/org.openhab.binding.ftpupload/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.openhab.binding.ftpupload</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ds.core.builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<binding:binding id="ftpupload" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:binding="http://eclipse.org/smarthome/schemas/binding/v1.0.0"
xsi:schemaLocation="http://eclipse.org/smarthome/schemas/binding/v1.0.0 http://eclipse.org/smarthome/schemas/binding-1.0.0.xsd">

<name>FTP Upload Binding</name>
<description>This binding is for receiving files via FTP.</description>
<author>Pauli Anttila</author>

<config-description>
<parameter name="port" type="integer" min="1" max="65335">
<label>TCP Port</label>
<description>TCP port of the FTP server</description>
<default>2121</default>
</parameter>
<parameter name="idleTimeout" type="integer" min="0" max="65335">
<label>Idle timeout</label>
<description>The number of seconds before an inactive client is disconnected. If this value is set to 0, the idle time is disabled.</description>
<default>60</default>
</parameter>
</config-description>
</binding:binding>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<thing:thing-descriptions bindingId="ftpupload"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:thing="http://eclipse.org/smarthome/schemas/thing-description/v1.0.0"
xsi:schemaLocation="http://eclipse.org/smarthome/schemas/thing-description/v1.0.0 http://eclipse.org/smarthome/schemas/thing-description-1.0.0.xsd">

<thing-type id="imagereceiver" extensible="image-channel, image-received">
<label>Image Receiver</label>
<description>Receive image files via FTP.</description>

<channels>
<channel id="image" typeId="image-channel" />
<channel id="image-received" typeId="image-received" />
</channels>

<config-description>
<parameter name="userName" type="text" required="true">
<label>User Name</label>
<description>Username</description>
</parameter>
<parameter name="password" type="text" required="true">
<label>Password</label>
<description>Password</description>
<context>password</context>
</parameter>
</config-description>
</thing-type>

<channel-type id="image-channel">
<item-type>Image</item-type>
<label>Image</label>
<description>Image received via FTP</description>
<state readOnly="true"></state>
<config-description>
<parameter name="filename" type="text" required="true">
<label>Filename</label>
<description>Filename to match received files. Supports regular expression patterns.</description>
<default>.*</default>
</parameter>
</config-description>
</channel-type>
<channel-type id="image-received">
<kind>trigger</kind>
<label>Image file received trigger channel</label>
<event>
<options>
<option value="IMAGE_RECEIVED">Image received</option>
</options>
</event>
<config-description>
<parameter name="filename" type="text" required="true">
<label>Filename</label>
<description>Filename to match received files. Supports regular expression patterns.</description>
<default>.*</default>
</parameter>
</config-description>
</channel-type>

</thing:thing-descriptions>
29 changes: 29 additions & 0 deletions addons/binding/org.openhab.binding.ftpupload/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Manifest-Version: 1.0
Bundle-ActivationPolicy: lazy
Bundle-ManifestVersion: 2
Bundle-Name: FTP Upload Binding
Bundle-SymbolicName: org.openhab.binding.ftpupload;singleton:=true
Bundle-Vendor: openHAB
Bundle-Version: 2.3.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ClassPath: .,
lib/ftplet-api-1.1.0.jar,
lib/ftpserver-core-1.1.0.jar,
lib/mina-core-2.0.16.jar
Export-Package:
org.openhab.binding.ftpupload,
org.openhab.binding.ftpupload.handler
Import-Package:
org.apache.commons.lang,
org.eclipse.jdt.annotation;resolution:=optional,
org.eclipse.smarthome.config.core,
org.eclipse.smarthome.core.library.types,
org.eclipse.smarthome.core.thing,
org.eclipse.smarthome.core.thing.binding,
org.eclipse.smarthome.core.thing.binding.builder,
org.eclipse.smarthome.core.thing.type,
org.eclipse.smarthome.core.types,
org.eclipse.smarthome.io.net.http,
org.osgi.service.component,
org.slf4j
Service-Component: OSGI-INF/*.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.xml
174 changes: 174 additions & 0 deletions addons/binding/org.openhab.binding.ftpupload/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
# FTP Upload Binding

This binding can be used to receive image files from FTP clients.
The binding acts as a FTP server.
Images stored on the FTP server are not saved to the file system, therefore the binding shouldn't cause any problems on flash based openHAB installations.

## Supported Things

This binding supports Things of type ```ftpupload```.
Every Thing is identified by FTP user name.
Therefore, every thing should use unique user name to login FTP server.

## Discovery

Automatic discovery is not supported.

## Binding Configuration

The binding has the following configuration options:

| Parameter | Name | Description | Required | Default value |
|-------------|--------------|------------------------------------------------------------------------------------------------------------------------|----------|---------------|
| port | TCP Port | TCP port of the FTP server | no | 2121 |
| idleTimeout | Idle timeout | The number of seconds before an inactive client is disconnected. If this value is set to 0, the idle time is disabled. | no | 60 |

## Channels

This binding currently supports the following channels:

| Channel Type ID | Item Type | Description |
|-----------------|--------------|----------------------------------------------------------------------------------------|
| image | Image | Image file received via FTP. |

When an image file is uploaded to FTP server, the binding tries to find the channel whose filename matches the uploaded image filename.
If no match is found, no channel is updated.
The filename parameter supports regular expression patterns.
See more details in the Things example.

Image channel supports following options:

| Parameter | Name | Description | Required | Default value |
|-------------|--------------|--------------------------------------------------------------------------|----------|---------------|
| filename | Filename | Filename to match received files. Supports regular expression patterns. | yes | .* |


### Trigger Channels

| Channel Type ID | Options | Description |
|-----------------|------------------------|-----------------------------------------------------|
| image-received | IMAGE_RECEIVED | Triggered when image file received from FTP client. |

When an image file is uploaded to FTP server, the binding tries to find the trigger channel whose filename matches the upload image filename.
If no match is found, no channel is updated.
The filename parameter supports regular expression patterns.
See more details in the Things example.

Trigger channels supports following options:

| Parameter | Name | Description | Required | Default value |
|-------------|--------------|--------------------------------------------------------------------------|----------|---------------|
| filename | Filename | Filename to match received files. Supports regular expression patterns. | yes | .* |

## Full Example

Things:

```
Thing ftpupload:imagereceiver:images1 [ userName="test1", password="12345" ] {

Thing ftpupload:imagereceiver:images2 [ userName="test2", password="12345" ] {
Channels:
Type image-channel : my_image1 "My Image channel 1" [
filename="test12[0-9]{2}.png" // match to filename test12xx.png, where xx can be numbers between 00-99
]
Type image-channel : my_image2 "My Image channel 2" [
filename="test.jpg"
]
Trigger String : my_image_trigger1 [
filename="test12[0-9]{2}.png"
]
Trigger String : my_image_trigger2 [
filename="test.jpg"
]
}
```

Items:

```
Image Image1 { channel="ftpupload:imagereceiver:images1:image" }
Image Image2 { channel="ftpupload:imagereceiver:images2:my_image1" }
```

Rules:

```
rule "example trigger rule 1"
when
Channel 'ftpupload:imagereceiver:images1:image-received' triggered IMAGE_RECEIVED
then
logInfo("Test","Image received")
end

rule "example trigger rule 2"
when
Channel 'ftpupload:imagereceiver:images2:my_image_trigger1' triggered IMAGE_RECEIVED
then
logInfo("Test","Image received")
end

```

Sitemap:

```
Frame label="FTP images" {
Image item=Image1
Image item=Image2
}
```

## Use case example

The binding can be used to receive images from network cameras that send images to a FTP server when motion or sound is detected.

Things:

```
Thing ftpupload:imagereceiver:garagecamera [ userName="garage", password="12345" ]
```

Items:

```
Image Garage_NetworkCamera_Motion_Image { channel="ftpupload:imagereceiver:garagecamera:image" }
```

Rules:

```
rule "example trigger rule"
when
Channel 'ftpupload:imagereceiver:garagecamera:image-received' triggered IMAGE_RECEIVED
then
logInfo("Test","Garage motion detected")
end
```

Sitemap:

```
Frame label="Garage network camera" icon="camera" {
Image item=Garage_NetworkCamera_Motion_Image
}
```

## Logging and Problem Solving

For problem solving, if binding logging is not enough, Apache FTP server logging can also be enabled by the following command in the karaf console:

```
log:set DEBUG org.apache.ftpserver
```

and set back to default level:

```
log:set DEFAULT org.apache.ftpserver
```

If you meet any problems to receive images from the network cameras, you could test connection to binding with any FTP client.
You can send image files via FTP client and thing channels should be updated accordingly.


49 changes: 49 additions & 0 deletions addons/binding/org.openhab.binding.ftpupload/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>About</title>
</head>
<body lang="EN-US">
<h2>About This Content</h2>

<p>Nov 10, 2016</p>
<h3>License</h3>

<p>The openHAB community makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
indicated below, the Content is provided to you under the terms and conditions of the
Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>

<p>If you did not receive this Content directly from the openHAB community, the Content is
being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
apply to your use of any object code in the Content. Check the Redistributor's license that was
provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
indicated below, the terms and conditions of the EPL still apply to any source code in the Content
and such source code may be obtained at <a href="http://www.openhab.org/">openhab.org</a>.</p>


<h3>Third Party Content</h3>
<p>The Content includes items that have been sourced from third parties as set out below. If you
did not receive this Content directly from the openHAB community, the following is provided
for informational purposes only, and you should look to the Redistributor's license for
terms and conditions of use.</p>
<p><em>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You include 3 jars, so it would be good to have also 3 entries here - to me it is not clear, where ftpled comes from (FTP Server or from MINA?).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

<strong>Apache MINA</strong> <br/><br/>
<a href="http://mina.apache.org">Apache MINA</a> under
<a href="http://www.apache.org/licenses/">Apache License</a>.
</em></p>
<p><em>
<strong>Apache FtpServer</strong> <br/><br/>
<a href="https://mina.apache.org/ftpserver-project/">Apache FtpServer</a> under
<a href="http://www.apache.org/licenses/">Apache License</a>.
</em></p>
<p><em>
<strong>Apache Ftplet</strong> <br/><br/>
<a href="https://mina.apache.org/ftpserver-project/ftplet.html">Apache Ftplet</a> under
<a href="http://www.apache.org/licenses/">Apache License</a>.
</em></p>
</body>
</html>
10 changes: 10 additions & 0 deletions addons/binding/org.openhab.binding.ftpupload/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
source.. = src/main/java/
output.. = target/classes
bin.includes = META-INF/,\
.,\
OSGI-INF/,\
ESH-INF/,\
about.html,\
lib/ftplet-api-1.1.0.jar,\
lib/ftpserver-core-1.1.0.jar,\
lib/mina-core-2.0.16.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading