General ideas on how to create a web app that receives data from Sigfox

I have a very general question: I bought a core module and a sigfox module. I have created a simple firmware that when I click the button I send temperature value from the internal sensor to the sigfox cloud.
What I want to do is to build a simple web app that would receive the message via a webhook from the MySigfox Big Clown service. Then I would display the measured value at the web app’s web page.
I have taken some basic Heroku and AWS tutorials to understand how to create a webapp that would do this, but I still can’t understand how to put together the individual pieces of files/code to actually create an app.
I have knowledge of HTML, CSS, JavaScript, Java, C and SQL and now I need to learn how to put these skills together and build a webapp. Could you provide with some advice what I should learn next or with some examples of web apps that do similar thing? I am trying to figure out the best way to tackle this problem, so some advice that would help me find the correct way would be much appreciated :slight_smile: Thanks!

Here you can be inspired, as backend is used google app script and data is stored in google sheets
https://doc.bigclown.cz/sigfox-pulse-counter.html

We plan further backend samples.

Hello,
it depends what the application has to do. This is my opinion based on experience during few automation web pages I built years ago…

In case you would like to display just the current state or value and control some outputs then it is ok to create your web app from scratch. In case you would like save values, display graphs and average values it is better to use some off the shelf system, like Grafana (https://doc.bigclown.cz/grafana-influxdb.html). I did some time series database with SQL and it is not easy and its slow compared to other DBs. It is better to use optimized database which is great for storing data but not changing them, like InfluxDB or others.

So what language do you like to use for you app? You mentioned Java, I don’t have experience there. I did some small services with Python and Flask - I’m total beginner in Python. Other option is to use NodeJs. Both languages can be run on Heroku. Then the next question is - do you need database?

Do you speak czech? Is the Grafana article useful for your or do you need further help? Let us know the more details of you project.

I really like the idea of using google app script as backend. I combined a Sigfox example firmware that I found on Big Clown GitHub and the google app script for sigfox pulse counter. But I can’t get it working:

My firmware is exactly the same as https://github.com/bigclownlabs/bcf-sdk-core-module/tree/master/_examples/sigfox

I have modified the script as following:

function doPost(e) {
var spreadsheets_id = ""; // I have inserted the spreadsheet id here
var device_id = ""; // I have inserted the 6 digit Sigfox id here

var content = e.postData.getDataAsString();
var payload = JSON.parse(content);

if (payload.device != device_id) {
  return;
}

var data = payload.data;
var buffer = [];

for (var i=0; i<24; i+=2) {
  buffer.push(payload.data.slice(i, i+2));
}

var head = parseInt(buffer[0], 16);

if (head != 0x00) {
  return;
}

var temperature = parseInt(buffer[4] + buffer[3] + buffer[2] + buffer[1], 16);

var ts = new Date(payload.time * 1000);
var date_time = Utilities.formatDate(ts, "Europe/Prague", "yyyy-MM-dd HH:mm:ss");

var doc = SpreadsheetApp.openById(spreadsheets_id);
var list = doc.getSheets()[0];
list.appendRow([date_time, head, temperature]);

return "ok";
}

But when I run the script, it gives me this message: TypeError: Cannot read property “postData” from undefined. (line 5, file “Code”)

And if I enter the web app URL to the browser, it gives me this: Script function not found: doGet

I found in Google Apps Script guide that a web app should comply with this condition: The function returns an HTML service HtmlOutput object or a Content service TextOutput object.

Is this the problem that the function doPost(e) doesn’t return a HTML service?

1 Like

Thanks for your ideas. I am thinking about learning Node.Js and yes, I would like to implement a database to store the measured values that I sent over with Sigfox.

The project is very simple: record temperatures measured by the core module sent over Sigfox and display them on a webpage. No graphs, just a table of values: time and temperature. What would be a way for a beginner like me to setup a database to store the values?

I looked at the Grafana article, but I would prefer to build a web app from scratch. I can follow the steps in the article, but I have no idea what I am actually doing.

Hi, actually this is a great idea to create documentation article for this.

I will do it as step-by-step tutorial on Heroku with Python and Flask framework. That should give you an idea how to create your simple web service for sensor data.

It will be ready in about a week or two :slight_smile:

1 Like

Hi, do you have any news on this topic? This tutorial would help me a lot :slight_smile:

But when I run the script, it gives me this message: TypeError: Cannot read property “postData” from undefined. (line 5, file “Code”)

The variable e exists only when the script is running as http request.

And if I enter the web app URL to the browser, it gives me this: Script function not found: doGet

This is correct if it only opens the url on which the script runs through the browser is the GET method. But the data from mysigfox is passed by POST then doPost. Use wget or curl for testing.

I found in Google Apps Script guide that a web app should comply with this condition: The function returns an HTML service HtmlOutput object or a Content service TextOutput object.

Is this the problem that the function doPost(e) doesn’t return a HTML service?

You are right, it would be better
return ContentService.createTextOutput(“ok”);
but return ‘ok’; it works too.

Is tutorial abowe working for someone?
For me it’s not. Data are sending to Sigfox, but not in Google Sheet.

Sheet: https://docs.google.com/spreadsheets/d/1hEYWHRbtK5764fnQIsm2KxegzPCIl547jazsOAVS3lo/edit?usp=sharing
Script: https://script.google.com/d/1yvkV1TFB_dsQVXXZTI3Bx8KYbkQr6yonOwMZBVo6P6B0Lcp2BpT_fFmT/edit?usp=sharing
Device ID: 21E26F

Hi, have you managed to resolve this issue?

If not, what happens if you try to send POST request to your sheet manually?