1

At first I do not want to do port forwarding to access my PI, what I want is that the PI would access a website where it would send the GPIO status and also will read the "new" values that must be set, based on data received from server. Ex. Pi would connect to www.mysite.com will post the GPIO status, this information would be displayed to user, also the user will set the GPIO's status that would be sent back to the Pi this must be almost instant or just 1-2 second delay between sending receiving data. POST pi GPIO status, GET GPIO status and set it. My question is if anyone has a good solution for this. I am using a shared hosting.


Ok, I think the solution is to use long polling, just in case if anyone will ask this in the future.

0

After reading your problem only one thing comes to my mind- CAYENNE It's a FREE cross platform IOT service where you don't have to write a single line of code and a very attractive GUI. Website: here You would not have to waste your time in port forwarding and leaving open ports / Vulnerabilities on your local network but would use the secure cayene server with password and KEY protection instead :D

  • You don't even provide a link to the cayenne web site. – Steve Robillard Dec 28 '16 at 22:09
  • No you did not. You provided a URL but did not make it a link. I care because as a moderator that is what I am here for and all caps is considered rude. – Steve Robillard Dec 29 '16 at 13:08
0

You have two way to reach your goal:

1- If you can develop it is easy : you can develop two web service on you server, on to set GPIO value and other to get current value, and in raspberry it is easy to call periodically those web services throw a thread loop.

2- If you aren't in convince with development you can search for a open source project and modify it, exemple the PIHome project : http://pihome.harkemedia.de or the PiHome+ project : https://sourceforge.net/projects/pihome-img/

0

Here's how I've implemented something similar using HA (Home Assistant) and a Telegram Bot:

Initial setup should be as simple as:

  1. Install HA (I first installed it before "hass.io" existed, using the simple process of creating a Python 3 virtualenv and running pip install homeassistant, but check the latest installation instructions and choose the method you prefer)
  2. Configure the HA components Telegram, Telegram chatbot, GPIO binary sensor, and GPIO switch.

By the end of this process you should have:

  • A working installation of HA, accessible on your local network at the address http://<Pi's IP address>:8123/.
  • Confirmed your GPIO switch is visible on the front page and that switching it on and off functions correctly.
  • Verified, using Developer Tools -> Services, that you can send a notification to your Telegram bot, using the service called notify.bluebot (replace "bluebot" with the name you configured), and then receive that message from your Telegram bot.
  • Verified, using Developer Tools -> States, that your GPIO status (binary_sensor.gpio_port or whatever you called it) is visible and correct.

Now create two HA automations, one which will send you the value of the GPIO sensor, and the other which will toggle the status of the switch.
You can create these in the HA UI, navigate to Configuration -> Automation, and click the round orange plus button to add a new one.

  1. Get sensor value
    • Triggers
      • Trigger type: Event
      • Event type: telegram_command
      • Event data: {"command": "/get"}
    • Conditions
      • Leave empty
    • Actions
      • Action type: Call service
      • Service: notify.bluebot
      • Service data: {"message": "{{ states('binary_sensor.gpio_port') }}"}
  2. Set sensor value
    • Triggers
      • Trigger type: Event
      • Event type: telegram_command
      • Event data: {"command": "/set"}
    • Conditions
      • Leave empty
    • Actions
      • Action type: Call service
      • Service: switch.toggle
      • Service data: {"entity_id": "switch.gpio_port"}

(Replace the names of the entities that I've used with the names you've assigned)

Now test that you can send your Telegram bot the command /get and have it respond with the status of your GPIO port, and send the command /set to have it toggle the GPIO switch.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.