[Solved] VoodooSpark setup troubles

Hi, friendly neighbourhood idiot here again!

I’ve had a look at the VoodooSpark and I just can’t figure it out at all.
I understand I can implement it and have it so I can use any programming language to directly control my Spark Core over a local network. However, I would prefer to have a Java application as my controller/server as it’s the only language I really know.

I have 2 areas I would like help with:

  • I’ve never used JavaScript before and was wondering if the short bit of code listed in the examples to blink and LED could be replicated in Java. If so I could work on it to do what I would like it to do.

  • Before I could get this far though the second step in the voodoo webpage uses a curl command to connect to the core though I don’t understand what to type for it to work for me.
    When I type “curl “https://api.spark.io/v1/devices/{DEVICE-ID}/endpoint?access_token={ACCESS-TOKEN}”” I get returned
    "{
    “ok”: false,
    “error”: “Variable not found”
    }"
    and if I remove “endpoint” from the command I get returned details about my core but not the required information (ie the IP or if it’s connected).

I’m not sure if I may be biting off more than I can chew but I was hoping this would be a straightforward thing to set up. Any help would be much appreciated.

Hi! Let’s see if I can help.

Area 1:
If you can initiate a TCP connection and send data (and probably receive data) using JAVA you can use VoodooSpark. If you are unsure I’d look into http://docs.oracle.com/javase/tutorial/networking/sockets/ . What you are trying to do is write a client which talks to the VoodooSpark server

Area 2:
Have you flashed the Voodoo spark to your core? And if so, is it sitting there happily breathing cyan? The error you are getting suggests to me that the VoodooSpark firmware isn’t on your core yet.

Thanks for replying @harrisonhjones

With a lot of help from looking about the place I previously managed to send strings of data to and from a Java server and the core through local TCP, but I am unsure how to turn this simple string into a function call, all I can do is see the String in the Serial monitor. Any ideas?

I will also have a look at what I have flashed to the core, all I did was copy and paste everything into the .cpp area.

Let me know how the flashing goes

As for talking to the VoodooSpark firmware. On the webpage you posted their is an API guide for interacting with it. You will need to use that API guide to write your java client. You won’t really be sending strings, you will be sending character or byte arrays.

For example, let’s say that you want to blink the D7 LED.

In your java client you would do the following (psuedocode)

  1. Do a call to “https://api.spark.io/v1/devices/{DEVICE-ID}/endpoint?access_token={ACCESS-TOKEN}” and parse the JSON to determine your core’s IP (you could also hard code this for testing)
  2. Connect to your core using either the above IP or a hardcoded one
  3. Change the PINMODE on the D7 by sending three bytes (0x00, 0x07, 0x01) over TCP to the SparkCore. The 0x00 indicates that it’s a pinmode command. 0x07 indicates that it’s pin 7 (D7) we want to change) and 0x01 indicates that we want it to be an output
  4. Bring the D7 LED high (on) by sending three byes (0x01, 0x07, 0x01) over TCP to the SparkCoe. Again, the 0x01 is a DigitalWrite command, 0x07 is the pin, and 0x01 is the state (1 for high, 0 for low).
  5. Wait a little bit (perhaps 1/2 a second)
  6. Bring the D7 LED low (off) by sending three bytes (0x01, 0x07, 0x00) over TCP
  7. Wait a little bit more
  8. Repeat from 4

I hope that helps. I want to also make it clear that I haven’t actually done this myself, I’m just reading from the VoodooSpark documentation but if you run into trouble I’ll be happy to flash it onto one of my cores and try it out.

I’ve gotten 1 step closer, I reflashed the firmware and can now get a response from the curl command. To make the Java class simple I do the curl command in CMD and the information from it straight into the Java code.
I’m sending the bytes of data but not seeing anything, my code here should only turn it on and that’s it.

I’m guessing I’ve missed something major for my Java client although I have left my .ino file for the Spark pretty blank too.

Just tests your code. Ended up flashing voodoo spark onto my core and got it works after some changes, namely that the voodoo spark uses TCP not UDP. See the pull request here: https://github.com/StudBeefpile/Voodoo-help/pull/1

Let me know how that goes!

Perfect! I can now use in my older code to see how well it will work with jsliders, I cant thank you enough!

Two last things, is there any way to make the voodoospark work without connecting to the spark cloud?
Also every so often my spark starts blinking cyan for around half a minute, once its back on the network I’m unable to connect to it or send it any data unless I reset it.

I’m not sure about your last blinking cyan issue.

As for the first part you are going to look into changing the system_mode (http://docs.spark.io/firmware/#advanced-system-modes). I believe, but I can’t remember, that SEMI_AUTOMATIC mode automatically connects to WiFi but not for the cloud. MANUAL mode might be best for you you will have to call the required WiFi methods to get it connected. Additionally, you won’t be able to pull down the Spark’s IP with a request to the API if you disconnect from the cloud

I’ll have a look into this then, thanks. Regarding the IP could I perhaps find a way to hard code in the IP in the Spark or try and get my program to search all IPs on a network and find out what one may be the spark?

Yes, I don’t believe the Spark responds to a ping anymore (TI changed that in the CC3000 firmware) but you could have your application search for the VoodooSpark firmware. I’d also be tempted to write your own “function” into the VoodooSpark that returns a name so you could automatically ID multiple cores running the firmware.

Hi @StudBeefpile and @harrisonhjones

You can definitely have a static IP address for the core–search to forum for the exact method. You can also configure your router to always give your core the same IP address via its MAC address.

Another way to handle this is to have your core broadcast a UDP packet with its IP address at startup or periodically so that the other host can discover it.

It was recently discovered that the core will answer ping requests if you start in manual mode. The reason for this is still not known. The MAC address (which is programmable but defaults to a TI owned address) will tell you if it is the core or not.

2 Likes

All good points. Listen to this guy @StudBeefpile!

Hi Guys:

I really want to see an example of using voodoospark from a webpage. Anyone got a simple webpage with buttons to turn D7 on and off?

By the way you don’t have to use curl to find your ip and port, just put this into the browser

https://api.spark.io/v1/devices/{DEVICE-ID}/endpoint?access_token={ACCESS-TOKEN}

Never got voodoospark working but did something similar at

https://community.spark.io/t/tcp-server-and-client-example-socket-programs-d7-on-please/11307/22

Really interested to try again with VoodooSpark. I really want Telnet to work, does anyone have any ideas, @harrisonhjones @StudBeefpile

Looking at the java code at https://github.com/StudBeefpile/Voodoo-help/blob/master/VoodooClient.java

if looks like the main text commands to get things going are:

Initialize:
0x00, 0x07, 0x01

turn D7 on:
0x01, 0x07, 0x01

Not sure about telnet baud rates parity etc. The IP address stuff is not a problem. If I can get this going, I want to try something similar using webpage Ajax or Sockets. Since I know my other code works from a web page I would like to see if I can get VoodooSpark working from a web page.