Permitted characters (eg. '@') in Inputs names?

I’m in the process of loading historic data from rayleighconnect.

As a first step I used the suggestion from Posting data in the emonCMS user guide to create the Inputs.

Rayleigh identify sensors with identifiers like “e2.freq”,“e2.i3p@1”,“e2.i3p@2”,“e2.i3p@3” so I decided to use “Rayleigh” as the node and keep those identifiers. My first attempt used the identifiers as is but the ‘@’ didn’t appear in emonCMS. My next attempt replaced the ‘@’ with ‘%40’ and used a URL like this:{"e2.freq":0,"e2.i3p%401":0,"e2.i3p%402":0,"e2.i3p%403":0}

Again, the identifiers appeared in emonCMS minus the ‘@’. Is this the expected behaviour?

It would be nice to use the same identifiers in both systems but isn’t essential. What are the permitted characters in Inputs names?

It’s a question that’s come up before, and I don’t think I’ve ever seen a definitive list. As far as I’m aware, nothing outside the plain set of alpha-numerical characters is guaranteed to be acceptable.

If you search for “emonCMS characters”, there are a few historic comments/discussions, only one directly related as I can see - but still not all that helpful.

@TrystanLea , @glyn.hudson ?

What you’ve run across is called percent-encoding.
The following characters are denoted as reserved, i.e. they have special meanings.

! # $ & ' ( ) * + , / : ; = ? @ [ ]

When a character from the reserved set (a “reserved character”) has a special meaning (a “reserved purpose”) in a certain context, and a URI scheme says that it is necessary to use that character for some other purpose, then the character must be percent-encoded.


1 Like

Thanks for the replies. I’m not clear which characters would need to be escaped in the fulljson part of the URL.

According to RFC 8259, The JavaScript Object Notation (JSON) Data Interchange Format:
A string begins and ends with quotation marks. All Unicode characters may be placed within the quotation marks, except for the characters that MUST be escaped: quotation mark, reverse solidus, and the control characters (U+0000through U+001F).

The ‘@’ character isn’t one that MUST be escaped within a JSON string (but it may be represented as “\u0040”).

PHP seems to be happy with ‘@’ in JSON strings:

pi@emonpi:/tmp $ php --version
PHP 8.1.26 (cli) (built: Nov 24 2023 13:12:14) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.26, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.26, Copyright (c), by Zend Technologies
pi@emonpi:/tmp $ cat hack.php
cat hack.php
$jsonobj = '{"e2.freq":0,"e2.i3p@1":0}';

pi@emonpi:/tmp $ php < hack.php
cat hack.php
array(2) {
pi@emonpi:/tmp $

In case the browser was doing something strange to the URL I tried curl but was unable to produce the equivalent of this example:


The pragmatic solution would be to replace the ‘@’ characters with ‘_’ characters. According to RFC 3986, Uniform Resource Identifier (URI): Generic Syntax both ‘_’ and ‘.’ are unreserved characters.

Here’s a curl example that works for me:

curl \
  --data 'node=mynode&fulljson={"power1":100,"power2":200,"power3":300}&apikey=xxxxxxxxxxxxxxxxxxxxxxx' \

Be careful not to post your API key - low risk, but better safe than sorry.

1 Like