arendst / Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
https://tasmota.github.io/docs
GNU General Public License v3.0
22.22k stars 4.81k forks source link

How to communicate via HTTP Requests #905

Closed luisfpinto closed 6 years ago

luisfpinto commented 7 years ago

Hello,

Is there any way I could communicate with sonoff to turn on/off the devices and the rest of functionalities doing HTTP Requests? I would like to integrate Sonoff into our mobile application

Thank you so much!

bontas69 commented 5 years ago

Update to 6.6.0 and reset default Bingo! syntax error... rule1 ON Button1#State DO WebSend [192.168.4.49:80] Power TOGGLE ENDON

sender log

09:16:06 CMD: rule1 ON Button1#State DO WebSend [192.168.4.49:80] Power TOGGLE ENDON 09:16:06 RSL: stat/sonoff/RESULT = {"Rule1":"ON","Once":"OFF","StopOnError":"OFF","Free":447,"Rules":"ON Button1#State DO WebSend [192.168.4.49:80] Power TOGGLE ENDON"} 09:16:14 RUL: BUTTON1#STATE performs "WebSend [192.168.4.49:80] Power TOGGLE" 09:16:14 RSL: stat/sonoff/RESULT = {"WebSend":"Done"} 09:16:50 RUL: BUTTON1#STATE performs "WebSend [192.168.4.49:80] Power TOGGLE" 09:16:50 RSL: stat/sonoff/RESULT = {"WebSend":"Done"}

receiver log

09:16:14 SRC: WebCommand from 0.0.0.0 09:16:14 RSL: Received Topic /Power, Data Size 6, Data TOGGLE 09:16:14 RSL: Group 0, Index 1, Command POWER, Data TOGGLE 09:16:14 MQT: u9149f/fb6/RESULT = {"POWER":"OFF"} 09:16:15 MQT: u9149f/fb6/POWER = OFF 09:16:15 CFG: Saved to flash at F4, Count 456, Bytes 3584 09:16:29 WIF: Checking connection... 09:16:29 WIF: Connected 09:16:51 HTP: Command 09:16:51 SRC: WebCommand from 0.0.0.0 09:16:51 RSL: Received Topic /Power, Data Size 6, Data TOGGLE 09:16:51 RSL: Group 0, Index 1, Command POWER, Data TOGGLE 09:16:51 MQT: u9149f/fb6/RESULT = {"POWER":"ON"} 09:16:51 MQT: u9149f/fb6/POWER = ON

Update: the rule disables local relay control,when push button, only websend does. Sonoff SV has available gpio4,5,14, so we can assign gpio4 as button2.Now rule1 became: rule1 ON Button2#State DO WebSend [192.168.4.49:80] Power TOGGLE ENDON sv button

Update: reverting to 6.4.18 rule does not work anymore! Works on 6.5.0!

meingraham commented 5 years ago

Strange, 6.4.18 has all the same rules features as 6.5. But glad it works.

But what about the tinycontrol /ay issue?

arendst commented 5 years ago

/ay has gone, foetsie, away, ins blaue hinein, disparu(e)

Has always been undocumented use. The correct used html interface is /cm as you found out.

meingraham commented 5 years ago

@arendst - well, good to know that it wasn't bizarre behavior by the device. Just making use of a feature that was never intended to be used... and now gone.

@bontas69 Do you need your tinycontrol system? If so, you'll have to follow up with them on why the %20 is being encoded as -600. Otherwise, you will not be able to make use of the /cm syntax.

Signing off.

Mike

bontas69 commented 5 years ago

REMOTE WIFI SWITCH -with two Sonoff SV

tested with tasmota 6.5.0 (6.6.0 get's some strange behaviour ,restarts but not sure) Sonoff SV supports 5-24V DC low voltage input, have pins for additional GPIO 4.5,14. sonoff_sv_5_

We'll use gpio4 configured as switch2 on sender gpio sv button_cr The pushbutton controls the relay as usual and the switch attached to sonoff will send commands to another tasmota device connected to the same wifi network.On the console paste the websend commands: rule1 on switch2#state=1 do WebSend [receiver ip:80] Power on ENDON rule2 on switch2#state=0 do WebSend [receiver ip:80] Power off ENDON enable the rules: rule1 on rule2 on

The rule above makes the switch open = relay on (close) . With the rules bellow switch open= relay off(open): rule1 on switch2#state=1 do WebSend [receiver ip:80] Power off ENDON rule2 on switch2#state=0 do WebSend [receiver ip:80] Power on ENDON

Application: An alarm PIR sensor when activated sends command wirelessly to a camera with DI (digital input) to record ,or some NVR with digital inputs. Or some light, siren whatever... Make it simple! Enjoy

meingraham commented 5 years ago

Since there are no switches on the Sonoff SV, you can define GPIO4 as Switch1

First pair: Rule1 on switch1#state do WebSend [receiver ip:80] Power %value% ENDON

Second pair can be combined into one rule set: Rule1 on switch1#state=0 do WebSend [receiver ip:80] Power on ENDON on switch1#state=1 do WebSend [receiver ip:80] Power off ENDON

bontas69 commented 5 years ago

Look's better...thanks Small improvements: Suppose the receiver is offline,the sender console look's like this: 07:41:21 RUL: SWITCH2#STATE=0 performs "WebSend [192.168.4.49:80] Power on" 07:41:27 MQT: u9149f/568/RESULT = {"WebSend":"Connect failed"} 07:41:28 RUL: SWITCH2#STATE=1 performs "WebSend [192.168.4.49:80] Power off" 07:41:35 MQT: u9149f/568/RESULT = {"WebSend":"Connect failed"} Would be nice some red flag in webgui of the sender or some kind of warning(buzzer alarm on the available GPIO5). Some rule On {"WebSend":"Connect failed"} do gpio5#state=1 endon...More fancy would be 1sec gpio on then 5sec gpio off , intermitent like an ups alarm. Another great feature would be the status of the additional switch (gpio4) on the web interface,preferably in different color. gpio_cr (Tasmota automatically assign a status of a new relay on webgui if it's assigned a new relay on the generic module--- ON/off status and toggle button---) relay

meingraham commented 5 years ago

The web UI is not actually intended as the "automation" UI, It's really a setup & troubleshooting interface. Only relays will have the control buttons.

Tasmota is first and foremost built as an MQTT based replacement. This is intended to send information to a "hub" and have it be the automation controller... including the UI. This automation hub can then perform all of the functions you are thinking of.

Remember that the ESP has limited program memory. The firmware has to remain small. In particular, since OTA is #2 on why Tasmota became widely used, the firmware has to stay under 650K so that it and a minimal copy can both reside in the 1MB flash concurrently during the OTA process. Thus, unless there is core automation commands that must be done on the device, then the philosophy is to offload that to a hub.

Mike

P.S. On your PSF A85, you could invert your relay component so that it follows your switch#state. P.P.S. Why do you have 8 relays defined? P.P.P.S. It's probably time to stop spamming this issue ;-) These kinds of philosophical conversations need to happen on Discord. I'm sure Adrian will soon lock this issue ;-)

bontas69 commented 5 years ago

Apologize.I'm just a noob.I don't have enough time to read and learn all forum,faq,documentation.I don't know much about mqtt,I have few sonoffs tasmota paired with the Lancontroller, they host a mqtt broker where device sends data.I went to discord...omg,too complicated.Allow me to give short answers here: PSF A85 is a tiny module based on ESP8285 (https://www.itead.cc/wiki/PSF-A85) PSF-A85_pinmap I made with PSF A85, an adjustable 3.3V dc-dc stepdown and td62084 IC(8ch Darlington Sink Driver) a flexible test board.The gpio from psf module are connected directly to the inputs of td62084. td62084 Datasheet:The TD62083AFNG and TD62084AFNG are high−voltage, high−current darlington drivers comprised of eight NPN darlington pairs. All units feature integral clamp diodes for switching inductive loads. Applications include relay, hammer, lamp and display (LED) drivers. The outputs of the TD62084 can drive directly relays, led's whatever. td62084_cr

For now I have only leds to check the output state. When 8 relays are allocated in module configuration we have 8 channels,I was just testing the environment. Thats the board,I have all the gpio's available... 20190723_220927 I agree esp devices are limited in program memory.I agree that every real life application demands custom solution. Would be nice a database with tested, real ,succesful projects where from a non-technical person can emulate , with step by step instruction, and use the device for it's own needs. I hope we'll continue conversation...maybe on discord. I'll try again... Please elaborate:"On your PSF A85, you could invert your relay component so that it follow you switch#state".

meingraham commented 5 years ago

Discord is just an interactive chat rather than this "stuttered" chat we've been having. Use this link to join the Tasmota server. It really is simple after you create your account.

Tasmota Support Discord Chat

Best to answer the relay invert question there to step through the setup interactively with you.