Solved: TCPClient connecting but not working with Pushingbox

Hi
Thanks for the primer. I am fairly new to microcontrollers and work full time so do not have much spare for my hobby. I just wanted to build a home automation and alarm system that would interface with a dvr. I have managed to get it all working but do not fully understand some aspects of how it all works yet (am studying furiously).
I understand what you are saying about variables, at the moment I am using multiple scenarios as you spotted. The pushingbox is set to send emails and push notifications, the latter being generally much faster and more appropriate for an alarm. I will have a look at your post on variables and see if I can make it work with my setup. Working out how to deal with the interrupts looks like more of a challenge but one well worth taking.
Regards

That's what coffee was invented for!

this is the method i use for the interrupt

    volatile boolean doorbellPressed = false;
    int doorbell = D0; // Doorbell button connects to D0 on the core
    
void setup() {
    pinMode(doorbell, INPUT_PULLUP); // other side of doorbell will connect to ground to pull low
    attachInterrupt(doorbell, doorbellpressed, FALLING);
    }

    void loop() {
    if (doorbellPressed) playDoorbell();
    //other stuff here
    }

    void doorbellpressed() {
        // this is the interrupt function
        doorbellPressed = true;
    }

    void playDoorbell() {
        doorbellPressed = false; //ready for next time
    // code here to play the tune
    }

That is a very good example of interrupts, much appreciated.
The interrupts in my project are in a library available on Github if you want to have a look. The author was so nice as to port his library for the spark. The code works perfectly alone but does not seem to work well with pushingbox, that is why I separated the code for two sparks. It has become a bit of a mess and I was hoping to have learnt a bit more than I have by now, but work has been ridiculous lately.
Seems that I need two interrupts, one for the radio receiver and one for pushingbox, or three if it were all to work on one spark ie transmit, receive, push. One observation is that considering the duration of the radio messages, the time it would take the spark to process the messages and the time that it should take to send the pushingbox message perhaps there is a bottleneck or problem in the code somewhere. I am fairly sure that the radio messages would never come in quicker than the spark could process them so I wonder if the pushingbox function is taking too long. If that were the case then presumably disabling transmit and receive when pushing would help. Now I see where the debug messages could be useful.
Regards

I have noticed it does take a few to a fair few seconds to send the request to pushingbox, i have the issue that i want to play the doorbell tune and send at the same time. i currently play the tune, then send a command to my tv to display the video, then send the request to pushingbox… so by the time i get the push notification the person (normally a courier in a mega rush) has gone.

You could just be lazy like me and use two sparks. We have a front door sensor and front pir both sending rf messages to arduinos controlling dvr ptz aswell as outside lights and sending pushingbox messages via a spark. Same as for all the other sensors at various levels of alarm setting. Often there are many concurrent messages flying around. With all that going on one spark would need a more learned programmer than me to achieve but I wonder if a RTOS would work. Must do some more research.
I find there is usually about a second delay between a sensor being triggered and a push message arriving on my phone. However sometimes they take several minutes and occasionally don’t arrive at all. Not good news for an alarm system!
Regards

BTW do you know if the delay occurs in the spark or pushingbox end? I have not got around to testing that. I always assumed that it must be pushingbox but now am not so sure.
Regards

Its both from what i have seen!

The DNS look-up takes ages sometimes (up to 4 seconds i have seen at home on cable internet connection)
Sometimes it cant resolve at all - doesnt send message
sometimes you get 400 bad something - doesnt send message
sometimes you get 200 OK and it takes up to 5 minutes
sometimes you get 200 OK and it takes a few seconds

I ported a DNS client for when I’m at work and the built in one times out / fails to resolve every time. that fixed the first 2 problems.
you could stop the 3rd one by parsing the response and looking at the 10th character… if its a ‘2’ then your looking a a 200 OK otherwise resend the request.
As for the delays at the PB end… maybe by buying lots of their notifon’s and making them super rich… they may upgrade the server

I have added a few lines to repeat on failed connections too. have a look at my post for the smart doorbell, there is full code on the hackster.io site for it

what phone are you receiving the notifications on? what app are you running for it?

Hi
I will take a look at your doorbell project.
I am using an app called newtifry on an HTC One M7
Cheers

I gave up on newtifry and newtifry pro because of the delays! now i send to G-mail which uses push to my phone so its only a few seconds to get the mail.

I plan (i have way to many plans) to set something up, probably with tasker, so when i receive the push/email it will open up the app for the IP camera at the front door…

That’s a great idea for tasker. I have incorporated your retry code into my spark alarm, I will keep you posted on any observations. I send to gmail and to newtifry. The newtifry notification comes in almost instantly and the gmail anything from a few seconds to a few minutes later. Although sometimes newtifry (or whatever) is slow or does not work.
PS two days in and seems to be working ok with the retry code, all good, thanks.