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?
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?
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.
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.
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.