Is it safe to place Spark Core Token number in a Webpage?

All things being strange to me as I don’t know the connection scheme so I have a question about it.

Is it a bad idea to place a core Token / ID No. in an unsecure html page ?

Generally saying, it is a bad idea to do so. In a “secure” (firewalled or secret) development environment, it would be okay. Device IDs are generally safe (although I still obscure mine), but the tokens should be guarded unless you want potential ne’er-do-wells to abuse your :spark:. Since you need a device ID and access token to access your :spark:, it never hurts to conceal both.

Thank you for giving me that good advise but, this causes a light to go off in my head and leads to more questions.

I can use php to pull this from a spark_confg.ini file that is not readable to world wide web.

So for anyone thinking of buying a used Spark Core in the future that’s going to be a bad idea as well ?

???

Can the Spark Core Token or ID be changed ?

And, does a Spark Core have a MAC Address ?

I could see some bad guy buying Spark Cores to obtain the Token & ID and then reselling them on craigslist or ebay with the intent of having a large platform to secretly hack or break the security ? or whatever devious purpose. They would have the persons name and in most cases address.

Not Good.

Good advice to keep your token secret! Here’s how to read you mac address:

  byte mac[6];
  Network.macAddress(mac);
  Serial.print("MAC=");
  for( int i=0; i<6; i++) {
    Serial.print(mac[i]>>4,HEX);
    Serial.print(mac[i]&0x0f,HEX);
    if (i != 5) {
      Serial.print(":");
    }
  }

Thanks @bko

I tired the MAC code in IDE but it has compile errors. I apologize as I am not sure exactly how to use it. Do I need to place this code within example code ?

Also, I password protected my spark webpage for now until I can code to include these parameters from a config file.

Here’s a complete sketch based on the code above. It prints the mac address every 5 seconds on the serial port.

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

void loop() {
    byte mac[6];
    Network.macAddress(mac);
    Serial.print("MAC=");
    for( int i=0; i<6; i++) {
        Serial.print(mac[i]>>4,HEX);
        Serial.print(mac[i]&0x0f,HEX);
        if (i != 5) {
            Serial.print(":");
        } else {
            Serial.println();
        }
    }
    delay(5000);
}

The output looks like this:

MAC=14:09:57:28:00:18
MAC=14:09:57:28:00:18
MAC=14:09:57:28:00:18
MAC=14:09:57:28:00:18

@bko

Than you very much. I will give it a drop, compile and display :slight_smile:

I’m not sure about the device ID on the :spark: itself, but you can change your access token via the web IDE. In the web IDE, click on the settings icon in the very bottom left, and then the access token should be obvious from there.

Thanks again. I will do a change from the IDE.

The device ID is hard-coded on the STM32, but in the long run this might become flexible, especially if we want to support other microcontrollers down the road.

I would say that for security purposes that you should keep your access token secret but feel free to publish the Core’s ID, because the ID doesn’t give anyone access without the token. The ID is like its URL, in the context of the Cloud. Knowing the URL doesn’t give you access unless you have proper authentication.

@zach

That’s really good to know as I will only have to conceal the token only.

Thanks

Bobby

Hi bko,
Very curious. How do you use take a look at the serial port read out? I know how it works with the Arduino IDE, but I didnt thought it is used for the spark.

HI @Wildfire

I am not 100% sure I understand your question but if you mean, how do you use the serial port for debugging without the Arduino IDE, then the answer is that you just need terminal program on your PC/Mac/Linux that you have plugged the USB cable from the spark into. Here’s the doc section:

Serial: This channel communicates through the USB port and when connected to a computer, will show up as a virtual COM port.

On my Mac, I usually use CoolTerm but there are lots of choices for all the common platforms. Folks have said that the Arduino IDE terminal program is not a good choice, but I have not tried it myself.

Did that answer your question?

@Wildfire

If your asking how to see the serial output from the Spark Core ? Use a tutorial by @BDub that explains how to install the Windows USB Port Driver and once that’s done you can use the Arduino IDE to see the Core’s output to the serial port; selecting just the COM PORT. https://community.spark.io/t/installing-the-usb-driver-on-windows-serial-debugging/882

Disclaimer: I am a Newbie and @bko @BDub have helped me with this too. (Credit Given)

Hello bko,
Thanks for your quick reply. Yes, I mend that I would like to use the serial port for debugging, like I normally use with my Arduino and the Arduino IDE. Do I correctly understand from you reply that it is possible to use the serial port option of the Arduino IDE with the spark core? (how do you do this, I am not able to select the COM port).
I’m using windows btw

edit: I just your reply spydrop. Thanks for the link, that was very helpful!

I only know what I know because of this Community is so helpful.

Your Welcome and don’t hesitate to ask for help.

Hi @Wildfire

If you are on Windows, I think you got the best answer from @spydrop and @BDub. If you are on a Mac instead just let us know and we will point you in the right direction.

Mmm, perhaps I jumped a bit too early. I got the spark driver installed and have port 6 and 7 for my two sparks. But I need to have the spark in blue flashing mode to select the port in Arduino IDE to open the serial monitor. But when I do this, I dont see any result in the serial monitor even though I flashed the spark with the firmware below. Is the firmware actually running when the spark is in blue flashing mode?

int count = 0;
void setup() {
Serial.begin(9600);
Spark.variable(“count”, &count, INT);
}

void loop() {
count = count + 1;
Serial.println(count);
delay(1000);
}

Nope! Flashing blue means that the Core is in Smart Config mode, and it is waiting to receive Wi-Fi credentials. In this mode, it’s not running user defined firmware. You can connect to the Core over Serial in this mode, but only to send your Core an SSID/PW or to read off your Core’s device ID.

If you flashed the code from above to your Core, it should open up a Serial connection that you can monitor using a Serial monitor like CoolTerm or Arduino’s IDE.

@Wildfire I would not use the arduino IDE for the Spark Core. Your best bet on windows in my opinion is Tera Term VT. To use the serial output over USB, it’s a little tricky on windows because if you are sending data before you open your serial terminal, windows thinks the port is in use already.

On my tutorial about halfway down where is says “DRIVER INSTALLED!!! NOW LET’S USE IT!” follow that part and try that code example. This effectively pauses the Spark Core while we open the Serial terminal. I’m going to amend that post and code in a second with a little trick I use now. While we are waiting to open the port, we might as well punch the background tasks:

void setup(){
  Serial.begin(115200);
  while(!Serial.available()) SPARK_WLAN_Loop();
}