How to use libraries(?) written in php?

Hey!

Here in Lebanon, electricity isn't available 24/7 which, as you can imagine, creates daily struggles. So that's why i want to create a device that will monitor the electricity and keep me updated via text message on my phone. In my research I stumbled across an API,on github, which is supposed to be whatsapp API but the problem is that this API has no .h or .cpp files and it is written in php.... So can i use this API? If so, how? if not, what are the best alternatives(besides GSM)?

Thanks in advance :)

You cannot run PHP code on an Arduino.

As you have not provided any links to stuff you are talking about I cannot help further.

I don't understand this "what are the best alternatives(besides GSM)?" - espcially in the context of your PHP question.

I'm GUESSING (and only GUESSING) that you plan to have a battery powered Arduino to monitor the power and send messages. But you need to explain what you want in detail.

...R

https://github.com/WHAnonymous/Chat-API This is the link to the github page

I meant by "what are the best alternatives(besides GSM)" - what are other ways I can send myself a text message, and no it doesn't have to do with php.

The project is: I setup my arduino on two outlets one that is only ON when there is electricity from the power plants and another outlet that has electricity from my backup generator,So when the electricity from the power plant is on the arduino texts me and tells that I have electricity from the power plant.And so far the best method to power the arduino is with a battery.

So the arduino checks wich outlet has electricity and then texts me which one is ON therefore I know where the electricity is coming from.

I've never dealt with an Arduino project on the internet, so I'm just getting ideas from what I read.

How about staring out with the Arduino Ethernet Shield? It plugs into the Arduino Uno or Mega, and uses the Ethernet library. It contains an SD CARD slot, where you can store files to be served on the internet.

I suggest getting a website where you can host your php files.

Then the process would go like this: (1) The power plant goes down. (2) Your battery-powered Arduino senses this on an input pin. (3) Your Arduino sketch uses this pin info to send a message to the shield. (4) The shield gets the appropriate file from it's SD Card and sends it over the internet to your website server. (5) You're website server recognizes the file, and then uses your php program to send a text message to you.

Ethernet won't work. Internet modems requires electricity which he doesn't have all the time.

Why not set up an Arduino (with the Ethernet shield) on the mains power? Have it bring up a simple web page (ie. "power is on"). Then connect to that page from time to time. Obviously if the power is off, the page won't come up.

For that matter, just ping the router.

mero55: I meant by "what are the best alternatives(besides GSM)" - what are other ways I can send myself a text message,

A lot depends on what systems are available when the power fails - because there must be a working system to receive a message as well as to send it.

My guess is that the GSM system would probably be the most reliable - but you are the person with information about what works and does not work in your country.

so when the electricity from the power plant is on the arduino texts me and tells that I have electricity from the power plant

I presume you don't plan to get a text message every minute while the power plant is working. I would have thought that your code should only send a message when the system switches to the standby power.

Alternatively you could arrange so it sends a message in response to a query from you. That could also be done with SMS messages.

...R

No-one likes my idea? If you have a PC at home, leave it on and have it run a web server (Apache, for example). You can configure a PC to restart after a power outage.

Then all you have to do from the remote location is run some sort of script that attempts to connect to the web server every 5 or 10 minutes. If it fails, the power is off. Then this script sends you a text. Unless, of course, the place with the script also has lost power.

Well, then your idea of the Arduino which runs off batteries could still work. It tries to connect to the server on mains power, if it fails, it sends a text.

So that's why i want to create a device that will monitor the electricity and keep me updated via text message on my phone.

Just out of curiosity, why do you want to know? Are you going to ring the power company and complain?

[quote author=Nick Gammon link=msg=2293931 date=1435390935] No-one likes my idea? If you have a PC at home, leave it on and have it run a web server (Apache, for example). You can configure a PC to restart after a power outage.

[/quote]

Having the computer shutdown via power outage while it's on can't be good for the computer in the long run.

And how would it send the text with no Ethernet? he would definitely need gsm.

mistergreen: Having the computer shutdown via power outage while it's on can't be good for the computer in the long run.

If you live where the electricity supply is unreliable, what choice have you?

And how would it send the text with no Ethernet? he would definitely need gsm.

As I understand it, Nick intended that the absence of a reply would be evidence of a power outage.

...R

Robin2: As I understand it, Nick intended that the absence of a reply would be evidence of a power outage.

...R

yes, I get that but how would the arduino text the user? There is no internet. The user would need to use GSM. Hopefully the cell towers are still functional with the power outage.

Is there are hardware solution for reading power? Convert 220V AC to 5V DC?

I think cellular systems/towers have battery backup so they are probably a reliable communication method. For battery power, use a UPS made for PCs and maybe tap off of the internal battery for arduino power. An inexpensive LED night light and a photo resistor could be used for detecting when the main power is off.

An inexpensive LED night light and a photo resistor could be used for detecting when the main power is off.

Ahh, smart, like an optocoupler, kind of.

mistergreen: yes, I get that but how would the arduino text the user? There is no internet.

I believe Nick was assuming (rightly or wrongly) that there would be power where the script is run from but not where the server is located,

I agree with @Zoomkat that the cellular system is likely to have standby systems. But we await info on that point from the OP.

...R

Hey!

I've been reading through your replies and all of them are brilliant ideas,but so far i think using GSM or an ethernet shield are far more suitable for me than setting up a server,just because i really don't know how to set up a server and i dont have the requirements on me at the present.

The following is just me explaining the differences of both methods GSM and the internet,so you can skip it if u want:

As for GSM, i think i could get GSM shield and set the arduino to send me text message when the power is coming from the power plant or a backup generator. And here is how i think it should go: 1. Arduino monitors which electric wire is ON (main line from the power plant or another wire from the backup generator).

  1. When one of the wires is ON the arduino sends me an SMS, only once.
  2. Arduino checks periodically for a change - the main line is off while the line from the backup generator isn't or vice versa or of both of them are off. 4.if a change is detected the arduino sends me another SMS telling me the power is coming from.

On the other hand, Using the internet (of course by ethernet or wi-fi) i can do as recommended and send myself a message through e-mail,or even twitter - if thats possible(?). But by using the internet i would run into the issue which you guys pointed out which is powering on the router.But for that i think i can create a delay in the arduino code for about 4min. or so, giving enough time for the router to turn on, and thats when the arduino sends me the message. And yes this means i can't tell if both energy sources are down. End of explanation

I also want to point out that my house is almost always powered.Rarely do both sources fail,and i only get a blackout when the power source is shifting from the powerplant to the backup generator, and it usually last for less than a minute.

Long story short, I think I'll get myself an ethernet shield(or wi-fi) and use that, and i know it might not be the most reliable,but -like many most of us here- money is an obstacle and here in lebanon SMS is somehow cheap(30c) but i have to pay a monthly fee of about 17k LBP (about 12$) for my SIM card.And with electricity source changing almost 5 times a day- over 30 days.....that's quite a bill!

If you have any remarks please dont hesitate to share them with me. Thanks for all your replies, i really appreciate it ;) .

Sorry it took me awhile to reply....

Hey!

Just to be clear, using whatsapp from the github link needs a server to run?So i can't use it on the arduino.

Hey!

Just to be clear, using whatsapp from the github link needs a server to run?So i can't use it on the arduino.

You have no internet when the power goes out. You can't use WhatsApp php.

mero55: Just to be clear, using whatsapp from the github link needs a server to run?So i can't use it on the arduino.

The problem is not that you need a server. An Arduino can act as a server. The problem is that you CANNOT run PHP code on an Arduino. I told you that in Reply #1.

...R