1

First time poster - please let me know if I do anything wrong!

I am sending sensor data from a raspberry pi via MQTT to nodeRED running on IBM's Bluemix - this works fine, I can send the data to any of the databases available on NodeRED. I have created a website using SquareSpace and can create code blocks where I can insert javascript code.

I am just looking for any way to get the data that I have in my nodeRED flow to be displayed on my website. Ideally, I hope to have live graphs using d3.js.

I have looked into Cloudant, but can not seem to get the URL method of querying data to work using the javascript http request explained in this tutorial: https://www.kirupa.com/html5/making_http_requests_js.htm. I would rather use dashDB since it provides much more scope for interesting queries, but, again, cannot seem to find a way to get the data into the javascript code.

This is the only mention that I found of someone trying to do a similar thing: https://answers.squarespace.com/questions/4648/how-do-i-connect-a-developer-site-to-a-database.html. Unfortunately, there is no "parse" database node in NodeRED, and since everything else I'm working on in this project will be 100x easier if my database is one of the Bluemix NodeRED ones, I don't think this will work for me.

I looked into Websockets, and MQTT. I thought perhaps I could extract data from the database in NodeRED, send it via MQTT to IBM's IoTF platform, then somehow request it again from the javascript code in my SquareSpace code block, but that seems a bit crazy.

I am tied to using SquareSpace, and as mentioned above, sort of need to use dashDB/Cloudant.

Many thanks for any advice.

Community
  • 1
  • 1
majpoynton
  • 23
  • 5
  • Take a look at this question http://stackoverflow.com/questions/4070331/connect-to-cloudant-couchdb-with-node-js?rq=1 – data_henrik May 31 '16 at 09:12
  • @data_henrik Thanks, I had seen that but thought it would be nicer to use the built-in HTTP API of cloudant. After much Googling, I think I have a solution which works: (After adding include jQuery code in the SquareSpace code inject header) `$.getJSON('https://**myusername**.cloudant.com/?url=https://u:p@myusername.cloudant.com/**mydata**&format=js&callback=?', function(data) { //do something with my data });` Although I have no idea why that URL works. I read up a little about URI, but just put that together from the examples people gave. – majpoynton May 31 '16 at 13:28

2 Answers2

0

Because Cloudant has an HTTP API and JSON data, I think that is your best bet.

Since you can run your own JavaScript from your SquareSpace site, I recommend that you use Cross-Origin Resource Sharing with your Cloudant account. (Cloudant CORS documentation here.)

Basically, visitors to your site can query Cloudant directly, with the permissions that you grant via CORS. Cloudant may not be as flexible for reporting as dashDB, however I think using Cloudant Query and also map-reduce views, you should be able to build the sorts of reports or indexes that you need.

If you have other questions, feel free to ask follow-ups here! Good luck!

JasonSmith
  • 72,674
  • 22
  • 123
  • 149
0

I've had great success using Firebase with Squarespace as it's dead simple to work with and the real time aspect makes it quite amazing in the context of Static Sites or Squarespace.

Although it sounds like you could just hit the Cloudant API like you mentioned above, performance could be an issue and providing real time data from your sensors may not be ideal. (Keep in mind, I have no idea what you're trying to accomplish though).

I would consider hitting Firebase with your data on the backend, then using Firebase's Web API and d3.js on Squarespace. This way your Squarespace site's charts are live, and directly connected to Firebase. As you hit Firebase with sensor data with minimal work on Squarespace. Your charts would update in real time from you data or other database. I can't rave enough about Firebase in this context.

jasonbarone
  • 172
  • 3
  • 17
  • could you expand on where you got information about connecting squarespace and firebase. I am currently at square one needing to connect logins and customer purchase history. Any direction would be great, right now I am just following their documentation which is fine but if there was something specific to squarespace that would be fantastic. thanks – Nick Garver Sep 10 '16 at 16:46