GithubHelp home page GithubHelp logo

woopsa-protocol / woopsa Goto Github PK

View Code? Open in Web Editor NEW
49.0 49.0 20.0 7.74 MB

Woopsa is the first fully open-source object-oriented protocol for automation and the Internet of Things

Home Page: http://www.woopsa.org

License: MIT License

C# 71.67% HTML 3.75% JavaScript 10.36% Batchfile 0.01% C 10.15% CSS 0.06% C++ 1.06% TypeScript 2.93%

woopsa's People

Contributors

bouda19 avatar didier-mettler avatar fabien-chevalley avatar floriansegginger avatar francois-birling avatar jordan-hadjedz avatar lionelvonniederhaeusern avatar michael-brouchoud avatar p-h-maillefer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

woopsa's Issues

WoopsaServer.ClearCache() doesn't work as expected with WoopsaObjectAdapter

Currently, calling void WoopsaServer.ClearCache() doesn't work as expected when combined with a WoopsaObjectAdapter. It successfully clears the server's path cache, but the WoopsaObjectAdapter is not rebuilt like it should.

public class SmokeDetector
{
  public bool SmokeDetected { get; private set; }
  public int Battery { get; private set; }

  public SmokeDetector(int battery){
    Battery = battery;
  }
}

public class VentilationSystem
{  
  public VentilationSystem()
  {
    SmokeDetector = new SmokeDetector(100);
  }

  public bool Power { get; private set; }

  public SmokeDetector SmokeDetector { get; set; }
}

...

VentilationSystem system = new VentilationSystem();
WoopsaServer server = new WoopsaServer(system);

...

system.SmokeDetector = new SmokeDetector(50); // Changing the SmokeDetector
server.ClearCache(); 
// Unfortunately, /woopsa/read/SmokeDetector/Battery still 
// gives out 100 instead of 50 as expected, because the 
// WoopsaObjectAdapter still refers to the previous object

To fix this issue, public void WoopsaObjectAdapter.ClearCache() needs to be updated to empty its inner list of Items.

Implement support for multipart/form-data POST requests in WebServer

Currently, the C# WebServer does not support multipart/form-data-encoded POST requests. This makes it impossible for clients to send files to servers.

Supporting this method of POST requests should be optional as it requires some additional security checks (what happens if a user tries to upload a 1TB file? etc) and creation of additional Streams.

The HTTPRequest class could then contain a Files array of Streams allowing the programmer to act on these files, for example saving them to disk or parsing them on-the-fly.

Add support for OPTIONS requests in all Woopsa server implementations to support authentication

As of today, authentication in the Woopsa protocol does not work when using the JavaScript client (browser) library, if the server resides on a different domain-name than the page making the requests.

This is a situation which can appear when HTML pages are making requests to "independent" Woopsa servers.

The problem seems to come from the rather recent CORS specification (see this StackOverflow issue for some discussion on the subject)

The problem did not appear during earlier development as there was a bug in Chrome that made it not respect the CORS specifications 100%.

Technical details

When one wishes to make a cross-domain HTTP request from a JavaScript page, there are some security implications. To remedy this, the W3C has come up with a "great" solution that is CORS: Cross-origin resource sharing combined with pre-flight headers

What this means is that any XMLHTTPRequest (AJAX) request from a page may not be made to a server on a different domain directly. Instead, the browser needs to know if this request is "allowed". It does this by making an HTTP OPTIONS request before making the actual GET or POST request.

If a server accepts cross-domain requests, it should reply with something like

Access-Control-Allow-Origin: http://foo.com
Access-Control-Allow-Methods: GET, POST

But it should not execute any action. If this reply satisfies the browser, then it will make the actual request.

This doesn't seem like much of a problem in most cases, as current Woopsa server implementations treat OPTIONS requests like any others and actually already send these Access-Control-Allow-* headers in every situation. However, this could be a problem with the Invoke Woopsa action, since requests will be made twice.

The problem becomes really problematic when we add Authentication to a Woopsa server. This is because the CORS specification explicitly forbids user credentials to be sent in the OPTIONS request. Thus, Woopsa servers won't see any credentials and will just reply with HTTP error 401: Authentication Required.

Solving the problem

To solve this rather complicated problem, Woopsa servers need to be modified to handle OPTIONS requests in a clean way. Be careful, however, as this might have some high-level implications:

  • When an OPTIONS request is received by a server, it should send the currently-sent HTTP headers (Access-Control-Allow-Origin, etc.)
  • However, it should never take any action. For example, it should not actually invoke the method, write or read the variable. This is of utmost importance, as most browsers will issue the first request twice.

Work-around

To get around this problem, use the content-serving abilities of the different Woopsa server implementations to host JavaScript and HTML. This will make it so HTML+JS is hosted on the same domain as the Woopsa server, and will avoid this cross-domain CORS nonsense.

Allow for buffers longer than 32k in WoopsaEmbedded

Currently, WoopsaEmbedded uses WoopsaInt16 everywhere, including the content-length. This limits pages served through Woopsa to 32kB, which is not enough for serving scripts like jQuery.

It's necessary to work with WoopsaInt32's or find another mechanism that will allow to overcome this limit.

Add a read method which returns only the raw value

Now a read looks like:

GET /woopsa/read/Temperature

which returns:

{"Value":24.2,"Type":"Integer","TimeStamp":"Sat Jan 02 00:00:00 GMT+05:30 2010"}

I suggest to add a simplier read request which would returns only the raw value instead of the full JSON payload.

This read, called here rawread, would look like that instead:

GET /woopsa/rawread/Temperature

which would simply returns:

24.2

In my opinion, this could be valuable in two main aspects:

  1. It removes the need to have a JSON parser for simple use cases
  2. It permits a much lighter payload

This simplier request could be very useful for embedded systems with limited resources as well as for even quicker use of the web REST woopsa API for some simple use cases. Moreover, a raw value beeing also considered as a JSON object, this could still be used with a JSON parser as well.

Enhancement: dynamic properties

It would be nice to have option to define dynamic property. By dynamic I understand property that is resolved during program execution. Lets say I have server for PLC and I want to serve I/O. Instead of defining each I/O as bool, byte, word i would like to have one route lets say /io and based on request resolve it to proper value.

Using Woopsa as a bridge to OPC UA server

Hi, am interested in using Woopsa node server to bridge to OPC UA. The homepage has the tantalising statement: "Because Woopsa shares so many concepts with OPC-UA, you can also use it as a gateway server to connect your webapps to OPC-UA servers."

Is there any more information about how to do this? I'm happy to write some bridging code, but it's not clear how to get started.

Thanks

Arrays - how?

How can I represent "ARRAY [1..10] OF WORD" as Woopsa value? Its one of basic PLC types.

Subscribe method does not accept backslash in path

Problem description
It seems the Subscribe method from WoopsaClientSubscriptionChannel does not handle backslash in path. It doesn't throw an exception but it doesn't work at all.

It can be confusing because the output given by oMachine use backslash instead of slash and the Read method supports backslash as well.

Current behaviour:
client.SubscriptionChannel.Subscribe(@"Thermostat\SetPoint", (e, a) =>
{
...
});
=> KO

client.SubscriptionChannel.Subscribe("Thermostat/SetPoint", (e, a) =>
{
...
});
=> OK

var point = client.ClientProtocol.Read(@"Thermostat\SetPoint")
=> OK

Expected behaviour
Subscribe method should handle backslash in the path:

client.SubscriptionChannel.Subscribe(@"Thermostat\SetPoint", (e, a) =>
{
...
});
=> OK

Reference missing since update

Hi,

I updated, with nuGet, from ver like 1.1.9 to 1.1.11 and some references are now missing. Please let me know me the new ones.

  • new WoopsaDynamicObject(_client.Root);
  • WoopsaClientProperty property = [...]
    property.Change += subscription.Value;
  • WoopsaServer woopsaServer = new WoopsaServer(InfoConnection, PORTSORTER);
    woopsaServer.ClearCache();

Thank you.

How to use authentication with http, DotNet WoopsaDemoServer

I am running the DotNet WoopsaDemoServer. I type "AUTH [enter]". Then I write "http://127.0.0.1:54004/woopsa/read/Temperature" in Google Chrome. I get the response "{"Value":24.2,"Type":"Real"}". I expect that I should not get access to this data because I did not provide authentication with username and password.
After that I typed "noauth [enter]" and tried again, the Google Chrome showed a Sign In popup window.
Then I tried to disable the authentication but couldn't. I also tried to open Internet Explorer 11 every time I type auth or noauth, but the popup shows up every time.
Is there some sort of long delay before the authentication is enabled or disabled?
This is repeatable: When I start the program, the server requires notification immediately only when I type "auth [enter] noauth [enter]". Why? But I cannot turn the authentication off. I am using the latest Woopsa 1.2.

DateTime incompatibillity in C#

WoopsaValue check DateTime with invariant culture in WoopsaValue.cs

[...]
case WoopsaValueType.DateTime:
    DateTime.Parse(text, CultureInfo.InvariantCulture);
[...]

and after convert the string without any culture in WoopsaExtensions.cs

[...]
DateTime result;
if (DateTime.TryParse(value.AsText, null, DateTimeStyles.RoundtripKind, out result))
  return result;
[...]

This leads to erroneous behavior according to the cultures of the PC

MultiRequest Javascript Client

Hello,

Thank you for your awesome work.
Could you explain how to implement the MultiRequest method on a javascript client ?

Is it just by using:

client.MultiRequest(jsonarray, ....

Thank you in advance,

Chrome ERR_SSL_PROTOCOL_ERROR This site can’t provide a secure connection. localhost sent an invalid response.

When I am running the DotNet WoopsaDemoServer and I write "http://localhost:54004/woopsa/read/Temperature" in the Google Chrome browser (Latest Version 89.0.4389.72 (Official Build) (64-bit)), I get "This site can’t provide a secure connection localhost sent an invalid response. Try running Windows Network Diagnostics. ERR_SSL_PROTOCOL_ERROR".
This happens because the browser automatically changes http:// to https:// when I press enter. It works well if I write "http://127.0.0.1:54004/woopsa/read/Temperature".
You might put a warning in your Quick Start Guide.
This is not a problem in Internet Explorer 11. I haven't checked any other browsers.

WoopsaClientSubscription_Thread never ends

I use WoopsaClient from a WPF application and when I have shutdown my last window there are still woopsa threads running. This only happens when I have registered for subscription using the method or the Change event on the WoopsaProperty. I am disposing the WoopsaClient.

Allow selective caching on the WoopsaObjectAdapter

Currently, the CheckCache delegate can be used on the WoopsaServer to selectively choose which paths are cached or not.

However, in cases where one uses the WoopsaObjectAdapter (in the default WoopsaServer constructor for example), there is no way to selectively cache (or not) certain objects. This makes working with IEnumerables a bit complicated, as the whole cache needs to be cleared.

Send large content from Client to Server

Hi,

How can I send a file from Client to Server ?

I try to send my file as a string, but the request buffer seems to be too small, is it limited to 10ko ?
So I try to upload my file using standard webclient.uploadfile but the server doesn't recognized this command.

How can I proceed to send a large file ?

Thank for the help,
Fabien

C# Collection mapping

Hello,
in my model I have some generic collections (List, Dictionary<TKey, TValue>, etc).
What are the best practices for mapping collections of objects?
Is it possible to have a simple example in which a collection is mapped and how to map and access its elements?

Thanks in advance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.