ThingSpeak Connection

I have two new cores. Both are connected to spark cloud and are breathing cyan. I have flashed both cores with the same code. When I flash the core I can see the flashing purple led. When the code is running I can see the Serial lines being printed to terminal window.

One of the cores runs all the code and will send updates to ThingSpeak. The other core does not want to play. If fails on the line: client.connect(“api.thingspeak.com”,80);

Complete code here (like I say one of the cores is processing this just fine, so I’m sure the code and my ThingSpeak creds are all OK)…

#include "math.h"
// Thinkspeak channel information
String writeAPIKey = "MYAPIKEYVALUES2O2BH9J"; // redacted
String channelID = "12345"; // redacted
 
// TCP socket initialize
TCPClient client;
 
float x;
float y;
 
/*--------------------------------------------------------
Setup
--------------------------------------------------------*/
void setup()
{
    Serial.begin(9600);
    delay(10000);
    Serial.println("===Starting===");
}
 
/*--------------------------------------------------------
Main loop
--------------------------------------------------------*/
void loop() 
{
    if(Spark.connected())
    {
        for (float z = 4.712; z < 10.995; z = z + .15)      // "z" sets the sin wave to the first zero crossing 4.712 and ends it on the next 10.995.
        {
          x = sin(z) * 127.5 + 127.5;                       // Making the sin wave all positive numbers and setting it to a scale of 0-255 (makes it easy to PWM an LED)
          y = 255 - (sin(z) * 127.5 + 127.5);               // This inverts the sin wave so we have two streams.
           
          // Must convert data to Strings, make sure you use capital "S" in Strings
          ThingSpeakUpdate("field1="+String(x)+"&field2="+String(y));
           
          // I put this delay in place so we don't flood Thingspeak but you should really use a timer, delays screw with the sparkcloud connection some times.
          delay(15000);
        }
    }
}
 
/*------------------------------------------------
Sends sensor data to Thingspeak
Inputs: String, data to be entered for each field
Returns: 
------------------------------------------------*/
void ThingSpeakUpdate(String tsData)
{
    Serial.println("Date string: " + tsData);
     
    Serial.println("...Connecting to Thingspeak");
     
    // Connecting and sending data to Thingspeak
    if(client.connect("api.thingspeak.com", 80))
    {
        Serial.println("...Connection succesful, updating datastreams");
         
        client.print("POST /update HTTP/1.1\n");
        client.print("Host: api.thingspeak.com\n");
        client.print("Connection: close\n");
        client.print("X-THINGSPEAKAPIKEY: "+writeAPIKey+"\n");
        client.print("Content-Type: application/x-www-form-urlencoded\n");
        client.print("Content-Length: ");
        client.print(tsData.length());
        client.print("\n\n");
         
        client.println(tsData); //the ""ln" is important here.
     
        // This delay is pivitol without it the TCP client will often close before the data is fully sent
        delay(200);
         
        Serial.println("Thingspeak update sent.");
    }
    else{
        // Failed to connect to Thingspeak
        Serial.println("Unable to connect to Thingspeak.");
    }
     
    if(!client.connected()){
        client.stop();
    }
    client.flush();
    client.stop();
}

Any ideas why this might happen?
Thanks,
M

@cuperman, is it always the same Core not connecting or is it that one Core connects and the other can’t?

@peekay123 it is always the same core that won’t connect.

@cuperman, you may want to reflash the CC3000 patch onto that Core. If you have Spark CLI and DFU-util installed, you can flash over USB with:

spark flash --usb cc3000

This will reset your credentials but hopefully fix the problem.

2 Likes

@peekay123 thanks, but dang. I don’t have node nor DFU-util installed and was hoping to avoid that whole complication. Is there anyway to check if the CC3000 patches are different on each core before I go through that effort?

@cuperman, from other posts it seems that sometimes, flashing the CC3000 image again solves the problem. The best way to do so is with CLI unfortunately. Have you tried a full factory reset, wifi setup and testing with just Tinker?

If you run this code with the USB serial monitor hooked up, you can tell if you TI CC3000 lost is mind for DNS service:

void setup() {
    Serial.begin(9600);
}

void loop() {
    IPAddress dnshost(ip_config.aucDNSServer[3], ip_config.aucDNSServer[2], ip_config.aucDNSServer[1], ip_config.aucDNSServer[0]);
    Serial.print(dnshost);    
    delay(10000);
}

// a value of 76.83.0.0 means DNS setup did not work

If you get 76.83.0.0, you definitely need to re-patch the TI part as @peekay123 said.

3 Likes

Thanks @bko I’ll give this a try first.

UPDATE:
The value of the broken core was indeed 76.83.0.0. Attempting the flashing now. (gulp)

UPDATE 2:
I got as far as the instructions for installing DFU - can’t believe how long winded it is. I’ve got no appetite for that right now. So seeing as this is a DNS issue I’ve changed tack and am using the ThingSpeak IP number instead of the URL. Connection is working as expected (reading values is not, but I’ll start a new thread on that).

3 Likes

spark flash --usb cc3000

I've got round to installing node and DFU-UTIL and was able to apply the deep_update_2014_06. Do I need to apply the CC3300 update too, or would that have been included as part of the deep update?

I did try the spark flash --usb cc3000 command but get a message back:

please specify a firmware file to flash locally to your core

I can navigate to that folder in my terminal window, but not sure where that lives? I have a cc3300_patch_programmer.bin file. Is that it?

Hi @cuperman

I think you need to update your Spark CLI since flashing “known” firmware like tinker or cc3000 is a newer feature.