Tiny WebServer code

Hmmm, @bko, should that not be static const char or const char to put it in flash :question:

Yes! Thanks – I made that edit. Firefox actually crashed twice while I was writing that post.

webClient.print("<html><body>BDub's Server Uptime: ");

I’ve tested this before and the compiler is smart enough to put string literals such as seen above into flash, if you didn’t want to have to create variables for everything.

1 Like

Hi,

I tried to put in static const char but I says it can’t comprehend with that much declarations (like 30 parts). I just put al the different lines in webClient.println(); commands as B​Dub suggested. I makes it easier to read then just putting it all in just one line like I previeusly did.

Eventually, it will be controlled by an app but at this stage this will be sufficient.

Next up! RTC :stuck_out_tongue:

greetz,
Marco

2 Likes

THANK YOU!

Can someone point me in the right direction to make a button to turn on a pin? Or something to listen to a pin or stream serial… A “Hello World” button itself would get me started in the right direction. I never thought about doing this. This is Awesome!

@rrace001,

Hi - Have you tried the Android Tinker App (offiical way) ? this app sets state of pins and on/off for you.

Or are you wanting to do it like you would with an Arduino with a web browser like I do (via the cloud) ?

Please let me know.

Hi @spydrop,

Yes, I have used the tinker App and have started looking at modifying it but then this came along. I would like to try it through a web browser. Hoping to broadcast audio and MIDI from the core eventually. I do not have experience in apps or browsers so getting the Tiny WebServer to work puts me far ahead of an app. Any info or direction or suggestions would be appreciated.

hi @rrace001,

First, I am not an expert at the core at all and I get reminded as such with pointer to better ways but, I am not a programmer of android java and never will be. I am an inventor who can do a website like here where I use jquery/css to turn on / off D4-D7 on my core: Link

I have not tried to stream audio or midi files from the core yet and I know others can tell you the slow rate of transfer the core does via the cloud but, I am with you. HTML URL access is the best way, why recreate the wheel when its in its 5th generation and I can do it.

Okay, enough with the pros & cons of using Tinker or a Website to control the core, I pick the website :smile:

Where to go depends on how you basically want to accomplish it.

  1. Is your core going to be accessed only on your local network or via the internet ?

  2. Will you be using HTML and PHP or Java or jquery to stream your audio / midi files ?

  3. Are dead against using an < iframe>url->external website< /iframe> ?

Using an < iframe> as you may already know allows the browser to run the code from the external website and not directly from the core but, it appears to be on the core. I did this in my examples on the Tinywebserver post - link above (Tinywebserver is not my code, it was provided by @BDub and its works great on the core).

The

___________________–

I would suggest getting Tinywebserver up and running on your local net and test it. and see what questions you need answered.

Hi @rrace001

Tiny WebServer is great, but you can also use a lot cloud features built into the core firmware. You might want to check out the Tutorial section here in the forum for some ideas.

1 Like

Hi @spydrop.

I’m searching for the ip of the spark core and can’t figure out why I can not find it, so hoping if you could help me? :smiley:

@darek_student, here is a simple way to get a Core’s IP address as per the documentation:

// PRINT THE CORE'S IP ADDRESS IN THE FORMAT 192.168.0.10
IPAddress myIP = Network.localIP();
Serial.println(myIP);    // prints the core's IP address

:smile:

3 Likes

HI @peekay123

I saw that too, but could not figure out where to write that, but by seeing that it says Serial.println i guess it must be connected through usb to lap and used with programs that are mentioned at the instructions too, please correct me if im wrong :smiley:

Btw due to not figuring out with that serial things i was trying to find in some other way.

So some advice about that i would appriciate.

If you have the cloud connection turned on, here’s an easy way to use Spark.publish() to get the local IP address:

void publishIP() {
    char printStr[64];
    IPAddress localAddr = Network.localIP();
    sprintf(printStr,"%d.%d.%d.%d", localAddr[0],localAddr[1],localAddr[2],localAddr[3]);
    Spark.publish("myIPAddr", printStr);
}

You could then read this with a browser like this:

[Edit to use events–2nd try sorry.]

view-source:https://api.spark.io/v1/devices/<<your device id>>/events/myIPAddr/?access_token=<<your access token>>
2 Likes

Ahh, you beat me to it! @bko Your publish example is better :slight_smile:

Edit: Oh, you provided a spark variable url, and not an events url I think

Thanks!
David

1 Like

@darek_student, using the USB serial approach makes debugging a lot easier. To use it, make sure you have the PC side setup with the correct drivers an software (I have Windows so I use Putty as a terminal) and you have Serial.begin(9600) in setup() to “open” the serial port.

I will often use a Digole smart display to output to since I can use it with Serial1 and connect it with a single wire (besides power and ground of course) to the TX line on the Spark. We have a great library for it as well.

1 Like

Thanks–fixed it just now.

Oh crap, I keep forgetting that side! @bko always makes me feel like a neanderthal :stuck_out_tongue:

1 Like

@bko great and simple way :smiley:

but i must ask is this normal or something is not right here, it keeps counting on and on instead of showing the IP ?

The event stream sends “keep-alives” every 9 seconds to avoid the browser closing the stream.

You can publish the IP address at any reasonable interval you want by calling that function every say 5 to 60 seconds.

In loop() do this to publish every 10 seconds (lastTime is declared as unsigned long globally i.e. before setup):

   unsigned long currTime = millis();
    if ( currTime-lastTime>10000) {
        lastTime = currTime;
        publishIP();
    }

If you only publish once, you have to be looking for it when it gets published.

2 Likes

Well I guess it’s because I don’t understand so good thouse instructions, and yup I’ve tried with putty to open the serial connection as it show in the instruction but it just did not want to open so I gave up from serial.

But thanks for advice :wink: