Transmit data (more than 1k) from core to phone app

Hello all,

I am wondering how I can transmit more that 1k of binary data form the core to a phone app that is not in the same local wifi network?
Spark.variable() works only for smaller amounts so it seems TCP or UDP is the right approach. A Spark.variable() could be then used to publish the IP address. But how can I connection socket in a ‘wide area’ network since WiFi.localIP() only gets me the local address?

Markus

If the phone isn’t on the same network I would suggest using an intermediate server. Push the bytes up to something like google app engine and then download them into your phone app.

You could always open port forwards to your Spark to allow external access, but this comes with many risks and isn’t ideal

I was working on a web sockets server in Node.JS that would allow for instant data exchange, whilst removing most limits, using web sockets also allows you to run behind almost any public networks which often lock down to only ports 80/443

@semaja2 is correct. You could also open up either ports to your phone or ports to your Core so that a direct connection can be acheived. Such port forwarding/opening usually requires a good relationship with you IT department, is often “impossible”, and exposes you to certain security risks.

@semaja2, got any code to share for that NodeJS proxy?

I guess even in a new thread you won't get answers a lot different to mine in your other thread

The answers of @harrisonhjones and @semaja2 do point you the same direction (port forwarding corresponds to globally reachable & intermediate server = push data to another server)

1 Like

Thank you all for brainstorming on those ideas. Do give you the bigger picture:
I am working towards a renewable energy project that involves a custom PCB where the spark will be plugged in. I am planning a launch on kickstarter and will later today share this under the ‘Product creation’ or ‘Project share’ topic.
I need to find the most reliable and hassle free way of getting the data to the phone app - finding a place in the ‘middle’ seems a bit to much work for the ‘end consumer’ of my project - it also might introduce additional subscription cost. The setup has to be as easy connecting the spark core with the wifi network.

Here is the link to the topic in ‘Product creation’

Sadly, if this is going to be an end consumer project you absolutely cannot except users to forward ports. I would suggest you throw something up in Google App Engine or a free Amazon EC2 instance and forward data back and forth that way.

You can send a few K of data via the cloud by using a combination of Spark.function() and Spark.variable(). Since all the data can’t fit into a variable (maximum size is ca 600 bytes) the Spark.function() is used to start the transmission, and to set the variable to the next block of data.

Something like

  • call “start” function to start transmission. This sets the “data” variable to the first part of data
  • phone app fetches the data variable, calls “next” function.
  • next function sets the variable to the next part of the data and returns the number of bytes available in the variable, say 200
  • phone app fetches the data variable again, calls “next” function which returns -1 to indicate no more data.

It’s a bit hacky, and not super quick, but it can be used to send a few K to consumers via the cloud. I used this technique to log a test report and make that available to the cloud. https://github.com/spark/firmware/blob/master/tests/libraries/unit-test/SparkParty.cpp#L132

I hope that helps, good luck!

3 Likes

This was discussed in the other thread already, too. Not in this detail and fn-var-combination, but it was.

That’s why it’s not good practice to re-ask the same question, just because you didn’t like the answers the first time.

One other point there was the need to transmit binary data, which does either call for replacing certain characters or multiply the payload by translating into string representation.