TCPServer isn't working

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); 
   digitalWrite(D7, LOW); 
   digitalWrite(D7, HIGH); 
   digitalWrite(D7, LOW); 
   delay(1000);  // give a few seconds to reflash the core if it gets unresponsive on startup
   digitalWrite(D7, HIGH); 
   digitalWrite(D7, LOW); 

  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 =;       // 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;

                   if (myInStr.indexOf("D7-ON") >= 0){   digitalWrite(D7, HIGH); }  
                   if (myInStr.indexOf("D7-OFF") >= 0){  digitalWrite(D7, LOW); }  



                if (myIncoming == '\n' && currentLineIsBlank) {

                    //client.println("<H1>Hello World.</h1>");   // use for debugging to check if http request can get returned

                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



<a  target="myI" href="{CORE-ID}/Address?access_token={ACCESS-TOKEN}" >Address</a><br>

<a  target="myI" href="" >D7-ON</a>...
<a  target="myI" href="" >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!

@Jelmertje I wrote that code a while back, not sure if it is the best option as it was written for small amounts of data, I don’t even remember if it worked well as I eventually made a really hacked socket for really fast but flaky communication with the Photon near the bottom of that topic.

What camera do you have setup with the Core? I have used the but that does not send images it sends smaller amounts of data about detected colours to the core/photon.

With my students I almost always used the html page ajaxbetter.html is the one to look at, but once again this is for small amounts of data.

For video I have always used other methods much better suited for this such as, or IVIDEO at or may have a solution.

See video at of a core with a cell phone as both the wifi hotspot and Skype setup to see what the car is seeing so you can drive the car over wifi

But these are not really connected with the Photon. Good luck, If I can get your camera I might be able to give some other ideas. I have several $3 web cams but I always hook them up using ivideon.

1 Like