RoArm-M3-S Python HTTP Request Communication

From Waveshare Wiki
Jump to: navigation, search

Python HTTP Request Communication

This chapter introduces how to use a Python demo to communicate with the robotic arm through HTTP requests.

HTTP (Hypertext Transfer Protocol) is a protocol for data communication on the Web, which is an object-oriented protocol on the application layer. It realizes wireless communication mainly based on the WiFi module in a simple, flexible Request-Response model.

Before running the Python demo, you need to install Python on your systems, configure the Python virtual environment, and install all the packages needed for demos. For more details, you can refer to the steps in RoArm-M3-S_Python UART Communication Control.


In the RoArm-M3-S Python demos, you can see that there are four Python demos, and the Python demo used for HTTP request communication is http_simple_ctrl.py. The demos are as follows:

import requests
import argparse


def main():
    parser = argparse.ArgumentParser(description='Http JSON Communication')
    parser.add_argument('ip', type=str, help='IP address: 192.168.10.104')

    args = parser.parse_args()

    ip_addr = args.ip

    try:
        while True:
            command = input("input your json cmd: ")
            url = "http://" + ip_addr + "/js?json=" + command
            response = requests.get(url)
            content = response.text
            print(content)
    except KeyboardInterrupt:
        pass


if __name__ == "__main__":
    main()

Before running the demo, you need to confirm the IP address of the robotic arm. To confirm that the IP address of the robotic arm is closely related to the WIFI mode in which the robotic arm is located. For more details, you can refer to RoArm-M3-S_WIFI Configuration.

  • If the WIFI mode of the robotic arm is only in AP mode, the IP address is 192.168.4.1;
  • If the WIFI mode of the robotic arm is in STA mode, the IP address of the robotic arm can be obtained on its OLED screen.

Use the following command to run the HTTP request communication program. The IP address in the command needs to be changed to the IP address of your robotic arm.

python http_simple_ctrl.py 192.168.4.1

Regardless of the mode, the robotic arm needs to be on the same LAN as the device on which the script is running.

800px-PythonHTTP1.png

After running, you can view the returned information, and then input the JSON commands, and you can get feedback from the robotic arm to communicate with the robotic arm.

For the meaning of more JSON format commands, please refer to the tutorial RoArm-M3-S_JSON Command Meaning .


Demo

RoArm-M3-S Tutorial