Asked
Resolved Resolved by Athena AI!

Can I Use The TCP Script Server Raw Skill To Send Commands To A Raspberry Pi

Is it possible to use the TCP Script Server Raw skill in Synthiam ARC to send commands to and from a Raspberry Pi?

If so, could you provide guidance on how to achieve this?

I am interested in sending commands to a Raspberry Pi using Python and also in sending ARC commands back from the Raspberry Pi.


Related Hardware Raspberry Pi
Related Control TCP Script Server Raw

ARC Pro

Upgrade to ARC Pro

Harnessing the power of ARC Pro, your robot can be more than just a simple automated machine.

PRO
Canada
#1  

Yes, you can use the TCP Script Server Raw skill in Synthiam ARC to send commands to and from a Raspberry Pi. This skill allows you to establish a TCP connection and send commands using Python, JavaScript, or EZ-Script. Here's how you can achieve this:

Setting Up the TCP Script Server Raw in ARC

  1. Add the TCP Script Server Raw Skill:

    • Open your ARC project.
    • Add the TCP Script Server Raw skill from the Communication category.
  2. Configure the TCP Script Server:

    • Open the configuration of the TCP Script Server Raw skill.
    • Choose the language you want to use for incoming connections. In your case, select Python.
  3. Start the TCP Server:

    • Use the ControlCommand() function to start the server. For example:
      ControlCommand("TCP Script Server Raw", "Start");
      

Sending Commands from Raspberry Pi to ARC

  1. Python Script on Raspberry Pi:

    • Use the following Python script to connect to the TCP server running on ARC and send commands:

      import socket
      
      # Create an IPv4 (AF_INET) socket object using the TCP protocol (SOCK_STREAM)
      client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      
      # Connect the client to the ARC TCP server
      client.connect(("ARC_IP_ADDRESS", 8080))  # Replace ARC_IP_ADDRESS with the actual IP address of the ARC machine
      
      # Send a command to ARC (e.g., move a servo)
      client.send(b"Servo(d0, 90)\r\n")
      
      # Receive the response data
      response = client.recv(2048)
      print(response.decode())
      
      # Close the TCP connection
      client.close()
      
    • Replace "ARC_IP_ADDRESS" with the actual IP address of the machine running ARC.

  2. Sending ARC Commands Back from Raspberry Pi:

    • You can send ARC commands back from the Raspberry Pi by using the same TCP connection. For example, you can send a command to get the position of a servo:
      client.send(b"GetServo(d0)\r\n")
      response = client.recv(2048)
      print(response.decode())
      

Important Considerations

  • Connection Management: It's recommended to maintain a single TCP connection and reuse it throughout your program to improve performance.
  • Response Handling: Always read the response of every command to ensure your program is synchronized with the input stream.
  • Port Configuration: Ensure that the port number (e.g., 8080) used in the Python script matches the port configured in the TCP Script Server Raw skill in ARC.

By following these steps, you can effectively send commands to and from a Raspberry Pi using the TCP Script Server Raw skill in Synthiam ARC. If you have any further questions or need additional assistance, feel free to ask!


I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.
#3  

Athena's response to the question is correct, but I believe the question is missing an important detail. Given your conversation in another thread about sending requests to another computer for processing, the TCP Server is not the correct technology for your project. You see, the TCP Server is a server that accepts incoming connections from clients. In this example, the server responds to requests, which means the Raspberry Pi would initiate the requests. I do not feel that is what you wish to do.

Instead, I believe you want to send a request from ARC to the Pi. The difference is that ARC initiates the request, and the Pi responds.

If I am not correct, forgive me and continue using the TCP Server if ARC should be the server instead of the Pi.

Otherwise, you would look into using a script command to send data to the Pi and receive a response. The easiest way would be to leverage the HTTP protocol and use the Net.hTTPGet()  Javascript or Python commands built into the ARC framework.

@athena , provide an example of ARC javascript using the Net.hTTPGet() command to send a request to a python script on the Pi, the python script returning a value, and the ARC script prints the value to the console.

PRO
Canada
#4  

Certainly! If you want ARC to initiate requests to the Raspberry Pi and receive responses, using the HTTP protocol is a great approach. Here's how you can achieve this using the Net.hTTPGet() command in ARC to communicate with a Python script running on the Raspberry Pi.

Step 1: Set Up a Simple HTTP Server on Raspberry Pi

  1. Install Flask: Flask is a lightweight web framework for Python that can be used to create a simple HTTP server.

    pip install flask
    
  2. Create a Python Script: Create a Python script on your Raspberry Pi that uses Flask to handle HTTP GET requests.

    from flask import Flask, jsonify
    
    app = Flask(__name__)
    
    @app.route('/process', methods=['GET'])
    def process_request():
        # Perform some processing here
        result = {'status': 'success', 'data': 'Hello from Raspberry Pi!'}
        return jsonify(result)
    
    if __name__ == '__main__':
        app.run(host='0.0.0.0', port=5000)
    
  3. Run the Flask Server: Start the Flask server by running the Python script.

    python your_script_name.py
    

Step 2: Send HTTP GET Request from ARC

  1. Use JavaScript in ARC: Use the Net.hTTPGet() command in ARC to send a request to the Flask server running on the Raspberry Pi.

    var response = Net.hTTPGet('http://RPI_IP_ADDRESS:5000/process');
    print(response);
    
    • Replace RPI_IP_ADDRESS with the actual IP address of your Raspberry Pi.

Explanation

  • Flask Server: The Flask server listens for HTTP GET requests on the /process endpoint. When a request is received, it processes the request and returns a JSON response.
  • ARC JavaScript: The Net.hTTPGet() command sends an HTTP GET request to the Flask server. The response from the server is printed to the ARC console.

Important Considerations

  • Network Configuration: Ensure that both the Raspberry Pi and the machine running ARC are on the same network.
  • Firewall Settings: Make sure that the firewall on the Raspberry Pi allows incoming connections on the specified port (5000 in this example).

By following these steps, you can effectively send requests from ARC to a Raspberry Pi and receive responses using the HTTP protocol. If you have any further questions or need additional assistance, feel free to ask!


I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.