Hello there,
I am currently working on a Photon project for school, and it involves sending image data from my photon to an HTML-page.
I have a Photon connected to a camera module. This module takes a picture, and then sends the data in packages containing bytes, to the Photon.
My current objective is to send this data from the Photon to an HTML-page, so that I can view the image.
My next objective will be a video stream to that HTML-page.
I haven't made up my mind about how I want to tackle this problem, but I've been investigating the possibility of using a TCPServer on my photon to send the byte array somewhere else.
An example I found on this topic here:
Shows a code that I can use to test it out, but unfortunately it does not seem to be working for me. On the html-page provided I can get the IP address from the cloud variable, but I cant seem to make requests to it.
What could be the problem?
The exact code I'm referring to is this:
TCPServer server = TCPServer(80);
TCPClient client;
char addr[16];
char myInput[30];
char myIncoming;
int myLoop1;
String myInStr;
void setup()
{
pinMode(D7, OUTPUT);
digitalWrite(D7, HIGH);
delay(1000);
digitalWrite(D7, LOW);
delay(1000);
digitalWrite(D7, HIGH);
delay(1000);
digitalWrite(D7, LOW);
delay(1000);
delay(1000);
delay(1000); // give a few seconds to reflash the core if it gets unresponsive on startup
digitalWrite(D7, HIGH);
delay(300);
digitalWrite(D7, LOW);
server.begin();
IPAddress localIP = WiFi.localIP();
sprintf(addr, "%u.%u.%u.%u", localIP[0], localIP[1], localIP[2], localIP[3]);
Spark.variable("Address", addr, STRING);
Spark.variable("myIn", myInput, STRING);
Spark.variable("myLoop1", &myLoop1, INT);
}
void loop() {
// listen for incoming clients
client = server.available();
if (client) {
myLoop1 = 0;
myInput[0] = '\0';
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
myIncoming = client.read(); // read from the http request
if (myLoop1 < 29 ){ // http request should be much longer than 29 characters!
myInput[myLoop1] = myIncoming; // put the character into an array
} else { // read enough information from the http request
myInput[myLoop1] = '\0'; // helps make a char array compatible with a string.
myInStr = myInput;
myInStr.toUpperCase();
if (myInStr.indexOf("D7-ON") >= 0){ digitalWrite(D7, HIGH); }
if (myInStr.indexOf("D7-OFF") >= 0){ digitalWrite(D7, LOW); }
}
myLoop1++;
if (myIncoming == '\n' && currentLineIsBlank) {
//client.println("<H1>Hello World.</h1>"); // use for debugging to check if http request can get returned
delay(1);
break;
}
if (myIncoming == '\n') { // you're starting a new line
currentLineIsBlank = true;
}
else if (myIncoming != '\r') { // you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
}
client.flush();
client.stop();
}
/*
MAKE THIS HTML PAGE TO COMMUNICATE WITH YOUR CORE
<a target="myI" href="https://api.spark.io/v1/devices/{CORE-ID}/Address?access_token={ACCESS-TOKEN}" >Address</a><br>
<a target="myI" href="http://192.145.1.65?D7-ON" >D7-ON</a>...
<a target="myI" href="http://192.145.1.65?D7-OFF" >D7-OFF</a><br><br><br>
<iframe name="myI" width=500 height=400></iframe>
I hope someone can point me in the right direction regarding this TCPServer example, but if someone has an entirely different idea to deal with my underlying objective: I am open to suggestions.
EDIT: I managed to get this example working on another WiFi network, so I'm going to continue exploring this path. If anyone can tell me why it might not work on certain networks, while it does on others, I'm still interested in that.
Thanks in advance!