Application concept Validation

Hi There,
new to Particle, although familiar with HW and FW programming and done some projects with Arduino etc…

Here is my application but not sure how to address this, in what is related to connectivity.

I will have some local processing where using SPI hw interface I will collect some data from a peripheral. Other peripheral is a I2C lcd, which I will use hw also, if possible.
So far so good, and I see it should be easy. I already saw some tips on hw use of spi, need to check i2c.
Periodically, I will post data to a local webserver, using a simple post, which will of course write on a DB.

My concern is the connectivity, and I think it is related to my lack of knowledge on this cloud service.

I understand I can program online, and part is connected to the cloud, which handles the downalod to the core. OK.

What I need is: this device, in real application won’t be connected to the internet but rather to a local network running a webserver, as I mentioned before.
My question is how I setup wifi to connect the module to, and also, how do I load code if I am on local network, and not cloud connected…

Thanks
:blush:

I do this with a couple of my cores.

The connecting to the db is done using the TCP client and you should find plenty of examples how to use it. Pretty sure I put up a bit of example code a while ago for db stuff for MySQL a search of the forum should find it

There are a few options to flash the device and I’ve always found dfu is the easiest and very quick. Otherwise you could use your phones hot-spot and have the core/photon connect to that to do the update then switch back to the other network

1 Like

Oh and use system mode semi-auto… turn the Wi-Fi on but don’t call particle connect and you will be fine.
You could connect a switch to call particle.connect that way you can download new code…

I think we will have a lot to talk hottie81 :smile:

For now, I am just not able to even install DFU and it seems nobody there with good ideas…
Windows system…

Problem is one… I am running out of time. I wanted this to be an improvement form system I have already using ESP8266 and other processor… but seems I am out of luck… :smile:

Thanks hootie81

Hi there…
Missing only SPI working…
When things work this dam thing is amazing :smile:
So I have I2C, TCPClient postingto a local webserver…all good.
I found that a get command takes a bit of time to execute…

Now my problem is I need to have all running not Internet connected.
I tried SEMI-auto, but not sure how to connect wifi only and use TCPClient…

Have a look at the docs “Reference” under WiFi and WiFi.connect() to do this


If you gave some more info about your OS and your problem there might have been …
e.g. this one (it also installs dfu-util and Particle CLI)

I Made it work few minutes ago, thanks.
Now, why is it so slow if not connected to the cloud? breathing green
Exactly same GET command/function… takes way more time to process…

Any ideas? I cannot do for instance 1 GET per second. If I am cloud connected all is good. And yes, it is working because I see data being added on db.

Thx

Your code is the key I’d guess, but we can’t see it :sunglasses:

here it is:

SYSTEM_MODE(SEMI_AUTOMATIC);

HttpClient http;
http_request_t request;
http_response_t response;

IntervalTimer myTimer;//event timer

void setup()
{
  if (WiFi.ready() == false)
        WiFi.connect();
  myTimer.begin(update_db_tmr, 5000, hmSec);
}
void loop()
{
    if (update_db_ready)
    {
        update_db();
        update_db_ready = false;
    }
}
void update_db_tmr()
{
    update_db_ready = true;
}

void update_db(){
    digitalWrite(D7,1);
    if (WiFi.ready() == true) 
    {
        request.hostname = "192.168.1.1";
        request.port = 80;
        request.path = "/writedb.php?write=" + String(aa++);
   
        // Get request
        http.get(request, response, headers);
    }
    else
    {
    }
    digitalWrite(D7,0);
}

OH… and after a little while App crashes. RED led blink and restart.
With Spark.connect() it doesn’t…

Are you sure this is the exact code, 'cause your setup and loop look a little ‘funny’?

because of formatting?
I removed dio signalling or lcd messages etc… which is useless for this matter…
I published the important piece.

Also, I guarantee that running this coed with 1sec interval fails in 2-3 cycles (populated was 5sec), whereas, running with Spark.connect instead of WiFi.connect runs smoothly, no problems…
Again I only replace WiFi.connect with Spark.connect… I actually would think that could take more since Spark could be exchanging some data with cloud…

HiScruffR,
all that has been solved.I also installed the toolchain… but trying to stay of that for now.
I am using DFU mode already, sice sometimes I get into manual mode or semi-auto and need to reflash using dfu.
All that is perfect. Thanks for the info anyway.

Cheers

this explains why other folks were mentioning WiFi stays on after disconnect spark…

void spark_connect(void)
{
    //Schedule cloud connection and handshake
    SPARK_CLOUD_CONNECT = 1;
    SPARK_WLAN_SLEEP = 0;
}

void spark_disconnect(void)
{
    SPARK_CLOUD_CONNECT = 0;
}

Now… will the next one explain why tcp GETs with WiFi.connect do not behave same speed etc… as Spark.connect?

 switch (mode)
    {
        case SAFE_MODE:
        case AUTOMATIC:
            SPARK_CLOUD_CONNECT = 1;
            SPARK_WLAN_SLEEP = 0;
            break;

        case SEMI_AUTOMATIC:
            SPARK_CLOUD_CONNECT = 0;
            SPARK_WLAN_SLEEP = 1;
            break;

        case MANUAL:
            SPARK_CLOUD_CONNECT = 0;
            SPARK_WLAN_SLEEP = 1;
            break;
    }

Ãnd what do you guys know about this compile option?

#ifndef SPARK_NO_CLOUD

does it work?

From what I see, only spent few minutes… but looks like WiFi interface might not be managed?? while using Spark Cloud class it would deal with it?

A lot of topics there :wink:

You don’t set pinMode() for this line.

I’d not use the IP as hostname. Rather put it into request.ip = IPAddress(), otherwise you’ll have a DN resolution attempt that will fail anyhow - this might well be the cause for the delay.
With Particle.connect() the TCP connection will be kept alive, while I’m not sure if HTTPClient does the same.

I can’t see declarations for update_db_ready, aa and headers - so this code can’t run (as @Moors7 pointed out already).
Can you test the code you posted and see if any of the problems go away? (e.g. crash, red blink)

If you’ve got a Photon, you’ve got Safe Mode to allow for OTA even if application fw would not get connected.

Got any link to such a topic? Since this is intended behaviour I’d be surprised if others would expect it to be any different.

Nope! When we want SPARK_CLOUD_CONNECT = 1; WiFi cannot be asleep, but without cloud we can start off with sleeping WiFi, but WiFi.on() or WiFi.connect() will wake WLAN but not connect to cloud - meaning SPARK_CLOUD_CONNECT = 0 and SPARK_WLAN_SLEEP = 0.

You’d have to see under what circumstances it gets set.

1 Like

Thanks ScruffR.

I know D7 is output only, but I would guess since I am not trying to make it input shouldn’t matter???

Yes, functions and variables are declared before.

I will try the ip address thing.Thanks. So just not sure how to do it. IPAdress function will return me Photon address? or how should i use it to return my webserver host?

Funny enough, if Spark.connect…all is good…

Thank you

Like this request.ip = IPAddress(192, 168, 1, 1);

If you keep your connection alive it might wirk without too.

HTTPClient.cpp contains this in the request function

  ...
    //
    // Send HTTP Headers
    //

    // Send initial headers (only HTTP 1.0 is supported for now).
    #ifdef LOGGING
    Serial.println("HttpClient>\tStart of HTTP Request.");
    #endif
    
    sendRequest(aHttpMethod, aRequest.path.c_str());

    // Send General and Request Headers.
    sendHeader("Connection", "close"); // Not supporting keep-alive for now.
    if(aRequest.hostname!=NULL) {
        sendHeader("HOST", aRequest.hostname.c_str());
    }
  ...

OK. IPAddress is kind of a parser.

Well, it didn´t work. Exactly the same. After a few cycles I get red leds…

About D7 pin mode, I misread your comment. I do set pin as output. (I read it like it is output only so you cannot set it…sorry)