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

Json keys and string values need to be wrapped in double quotes #199

Closed
yoavl opened this issue Jan 1, 2019 · 5 comments
Closed

Json keys and string values need to be wrapped in double quotes #199

yoavl opened this issue Jan 1, 2019 · 5 comments

Comments

@yoavl
Copy link
Contributor

yoavl commented Jan 1, 2019

Services written in different languages ​​(eg golang) are very strict on Json format and will throw error if there are no double quotes around the keys

@jeremypoulter
Copy link
Collaborator

jeremypoulter commented Jan 1, 2019

Just had a quick check and the few I looked at look are quoted correctly. Please can you give the specific endpoint that has an error?

@yoavl
Copy link
Contributor Author

yoavl commented Jan 2, 2019

The Function create_rapi_json()
In the current state the request is:

2019/01/02 12:20:14 GET /input/post.json?node=test&json={amp:0,wh:0,temp1:0,temp2:241,temp3:230,pilot:16,state:1,freeram:30616,divertmode:1}&apikey=72dle7b5d934bb0999f5oh3ca2078a96 HTTP/1.1
Host: 192.168.101.50:8081
Connection: close
Accept-Encoding: identity;q=1,chunked;q=0.1,*;q=0
Connection: close
User-Agent: ESP8266HTTPClient

I have changed the function:

create_rapi_json() {
  url = e_url;
  data = "";
  url += String(emoncms_node) + "&json={";
  data += "\\"amp\\":" + String(amp) + ",";
  if (volt > 0) {
    data += "volt:" + String(volt) + ",";
  }
  data += "\"wh\":" + String(watthour_total) + ",";
  data += "\"temp1\":" + String(temp1) + ",";
  data += "\"temp2\":" + String(temp2) + ",";
  data += "\"temp3\":" + String(temp3) + ",";
  data += "\"pilot\":" + String(pilot) + ",";
  data += "\"state\":" + String(state) + ",";
  data += "\"freeram\":" + String(ESP.getFreeHeap()) + ",";
  data += "\"divertmode\":" + String(divertmode);
  url += data;
  if (emoncms_server == "data.openevse.com/emoncms") {
    // data.openevse uses device module
    url += "}&devicekey=" + emoncms_apikey;
  } else {
    // emoncms.org does not use device module
    url += "}&apikey=" + emoncms_apikey;
  }

  //DEBUG.print(emoncms_server.c_str() + String(url));
}

Now the request is:

2019/01/02 12:30:49 GET /input/post.json?node=test&json={"amp":0,"wh":0,"temp1":0,"temp2":226,"temp3":230,"pilot":16,"state":1,"freeram":31328,"divertmode":1}&apikey=72dle7b5d934bb0999f5oh3ca2078a96 HTTP/1.1
Host: 192.168.101.50:8081
Connection: close
Accept-Encoding: identity;q=1,chunked;q=0.1,*;q=0
Connection: close
User-Agent: ESP8266HTTPClient

I checked the change in my existing account in data.openevse.com/emoncms and everything works as expected.
Now the new service I'm trying (written in golang) works great.

@jeremypoulter
Copy link
Collaborator

Ah that JSON ;-) I think that should be ok, may cause some issues with legacy setups but the current EmonCMS handes this OK, @glynhudson what do you think?

@yoavl
Copy link
Contributor Author

yoavl commented Jan 3, 2019

I also looked at the mqtt_publish() function, I think it will work fine there too.
Currently I do not have a way to check the MQTT service.

glynhudson added a commit that referenced this issue Jan 7, 2019
Resolve #199. Add escaped double-quote to the json string
@glynhudson
Copy link
Contributor

Great, thanks. I've just tested and emoncms handles it just fine. PR has been merged 👍

Stef-Sijben pushed a commit to Stef-Sijben/ESP8266_WiFi_v2.x that referenced this issue Apr 12, 2019
Stef-Sijben pushed a commit to Stef-Sijben/ESP8266_WiFi_v2.x that referenced this issue Apr 12, 2019
Resolve OpenEVSE#199. Add escaped double-quote to the json string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants