F. Gran F. Gran - 1 month ago 21
PHP Question

Calling Raspberry Pi from ASP.NET to send a SMS remotely

Just discovered the amazing

Raspberry Pi 3
and I am trying to learn how to use it in one of my projects.

Setup:


  • ASP.NET
    app on
    Azure
    .

  • RPi
    :


    • software:
      Raspbian
      ,
      PHP
      ,
      Apache 2
      , and
      MariaDB
      .

    • has internet access and a web server a configured.


  • 3G dongle for SMS sending, connected to the
    RPi
    .



Desired scenario:


  • when a specific button within the
    ASP
    app is clicked:


    • through
      jQuery
      $.ajax()
      the
      RPi
      's ip is called with the parameters
      phoneNumber
      and
      smsType
      .


  • then the
    RPi
    :


    • fetches the SMS text from a
      MariaDB
      database based on the
      smsType
      parameter.

    • invokes a
      Python
      script using the
      PHP
      exec("python sendSms.py -p phoneNumber -m fetchedText", $output)
      (i.e. with the phone number and the fetched text):


      • script will send the
        AT
        command(s) to the dongle.

      • script will return
        true
        or
        false
        based on the action of the dongle.



  • echo
    the
    $output
    to tell the
    ASP
    what is the status.

  • finally, the
    ASP
    will launch a
    JavaScript
    alert()
    saying if it worked or not.



This is what I need to accomplish. For most of the parts I found resources and explanations. However, before starting on this path I want to understand few things:


  • General questions (if you think they are not appropriate, please ignore this category):


    • What are the (logical) pitfalls of this scenario?

    • What would be a simpler way to approach this?


  • Specific questions:


    • Is there a size limit to consider when passing parameters through the
      url
      ?



Answer
  • What are the (logical) pitfalls of this scenario? My opion would be to pass the data and the two fields (phoneNumber and SmsType) through a POST request rather then an GET request because you can send more data in an post request and encapsulate it with JSON making it easier to handle the data.

  • What would be a simpler approch ? Maybe not simple but more elegant, extend the python script with something like flask and build the webserver right into the python script, saves you running a webserver with php!