Receiving data from app with PHP with HTTP API

Hello,

I’ve set up a local server and i am able to send data successfully with the HTTP API with PHP. I am wondering how can i do communication to the other direction with the HTTP API and PHP somehow.

Is it possible?

You’d need to poll the API on a regular basis to look for changes.
Don’t go crazy though, keep it to less than 10 API calls per second with the standard local server setup.

Pete.

Dear Pete,

that is what i’d avoid in the long run, running on a raspberry Pi, it will consume quite a bit of CPU unfortunately, therefor my passively cooled Pi (the new model tends to be rather hot anyway) will be burning (and W consumption will rise significantly ofc).

I’d have to go active cooling. Sorry for the absolute and total ignorance, but isn’t there something more practical? Shall I just use the library in some way to communicate, i will need to control GPIO pins anyway

You could install Node-Red and the Blynk plug-in for Node-Red. That way a write node would be triggered only when it’s value changed (via the app or an API call.
You could also use Node-Red to do the Blynk updates instead of API calls.

This is what I do, using MQTT messages to/from my devices to communicate with Blynk via Node-Red.
I don’t ripen a Pi v4, but my V3 runs fine with passive cooling and the Webmin interface shows around 1% CPU usage most of the time:

Pete.

1 Like

Thanks Pete, i was able the install Node-RED and the Blynk library and it seems it is working with my localserver, as I press the button I can see 1 or 0… :slight_smile: It would be nice to controll GPIO on the Pi directly from here but i figured out there is this “exec” node I can use to execute phyton scripts which will do for me.

Btw can I ask what kind of System Info interface am i looking at? I am running stock Raspbian and this would be a nice touch.

Thanks one more, you’ll hear from me soon!

One more quick question while we’re still at it, q
i’d like to, let’s say, set the color property of a value display widget based on it’s value. I read somewhere that I need to pass a hexidecimal value as msg.payload to achive this?

I have to leave for today but I’d like to get this done.

Thank you in advance!

/i think you should consider something like a Discord server where people can share thoughts, ideas, help each other, it would be awesome/

The web dashboard for the Pi is called Webmin. It was installed as part of Peter Scargill’s script, and I find it really useful, especially as I don’t know one end of a Pi from the other.
It allows you to stop/start processes, configure network settings, apply updates etc. etc.
A quick search gave these instructions on how to install it:

I’ve never used it, but I know there are ways of manipulating the Pi GPIOs via Node-Red. Maybe something like this:
https://nodered.org/docs/faq/interacting-with-pi-gpio

I’ll take a look at your second question later.

Pete.

Yes, the Node-red info in the sidebar displays help for the type of widget that you’ve selected and it explains things quite well for the Blynk nodes. You can either have multiple nodes configured to set different properties by passing the values as msg,payload, or you can use one Set Property node and pass the values as msg.color, msg.oblabel, msg.offlabel etc etc.

I’m not sure why your nodes aren’t connected up with bits of spaghetti though, making patterns with the spaghetti is the fun bit!

I’ve never used Discord, so probably don’t know what I’m missing, but TBH I really don’t have time to get involved in much more.

Pete.

Hi Pete,

yes, i’ve got it working like this:

first i forgot the hashtag before the HEX values, but now it’s working. :slight_smile:

But how the hell one adds && or AND in the IF switch? It’s pretty sad looking this way :smiley:

Have a nice day!

There are many ways to improve this :wink:

First of all, you don’t need three Set Property nodes on the right hand side. Just have one, that you call “Set colour” and feed the three Change nodes into this. At this point you have a lightbulb moment :bulb: and ask why the hell did I think I needed three of these,

Then, you can write a little function to set the msg.payload to the desired hex value. Something like this (warning, untested code follows!)…

if (msg.payload <50)
{
    msg.payload = "#04C0F8"; // Blue
    return msg;
}

if (msg.payload >=50 && msg.payload<200)
{
    msg.payload = "#23C48E"; // Green
    return msg;
}

if (msg.payload >=200 && msg.payload<500)
{
    msg.payload = "#ED9D00"; // Yellow
    return msg;
}

if (msg.payload >=500)
{
    msg.payload = "#D3435C"; // Red
    return msg;
}

Pete.

yee boiii :smiley:

Much neater!
Now you have some spare spaghetti to eat later :grinning:

Pete.