跳到主要内容

AI 驱动文档

您想了解什么?

通过 HTTP 使用 Node-RED 进行配方变更

本教程演示如何使用简单的 HTTP 请求远程改变 OV10i 摄像头的配方。你将构建一个系统,使网络中任意设备能够即时在不同的检测设置之间切换——非常适合包含多种产品的生产线。

What You'll Build: 一个远程配方切换系统,能够响应来自平板、计算机、PLC,或任何能够发送网页请求的设备的 HTTP 命令。

Estimated Time: 15-20 分钟

Skill Level: 初学者

Real Example: 想象一个操作员在平板上扫描条码,摄像头会自动切换到该产品的正确配方——这正是我们要构建的系统!

Why HTTP Recipe Changes Make Life Easy

OV10i 使远程配方切换变得简单:

  • Any device can trigger - 平板、PLC、计算机,甚至智能手机
  • Instant switching - 配方在不到一秒的时间内就切换
  • No complex setup - 只需在 Node-RED 中放置几个节点
  • Works with existing systems - 与你现有系统无缝集成

Perfect for: 多产品生产线、操作员控制面板、自动化系统,或任何需要快速配方变更的场景。

Prerequisites

在开始之前,请确保你具备:

  • OV10i 摄像头已连接并正常工作
  • 已创建并准备使用的配方不少于 2 个
  • Node-RED 访问权限(通过 IO Block)
备注

你需要的 recipe ID numbers - 这些编号在你编辑配方时的浏览器地址栏中可以找到。

Step 1: Find Your Recipe Numbers

1.1 Get Recipe IDs

  1. Open any recipe in Recipe Editor
  2. Look at your browser address bar
  3. Find the number after /recipe/ (example: /recipe/15 means Recipe ID is 15)
  4. Write down the IDs for all recipes you want to switch between

Why these numbers? Each recipe has a unique ID that never changes - this is what the camera uses internally.

Step 2: Open Node-RED

2.1 Access the Flow Builder

  1. In any Recipe Editor, click "IO Block"
  2. Click "Configure IO"

You're now in Node-RED where we'll build your recipe switching system!

2.2 Plan Your Setup

Here's what we're building:

Button Click → Format Request → Send to Camera → See Result

Simple! The camera has a built-in web server that listens for recipe change requests.

Step 3: Build Your Recipe Switcher

3.1 Add the Basic Nodes

Drag these 4 nodes onto your canvas:

  1. Inject (from Input section) - Your "switch recipe" button
  2. Function (from Function section) - Formats the request properly
  3. HTTP Request (from Network section) - Sends command to camera
  4. Debug (from Output section) - Shows if it worked

3.2 Connect Them Up

Wire them together like this:

Inject → Function → HTTP Request → Debug

Easy! Now let's configure each one.

Step 4: Configure Your Nodes

4.1 Set Up Your Recipe Button

  1. Double-click the Inject node
  2. Change name to "Switch to Recipe 15" (use your actual recipe ID)
  3. Set Payload to "15" (your recipe ID number)
  4. Click "Done"

4.2 Set Up the Request Formatter

  1. Double-click the Function node
  2. Name it "Format Request"
  3. Copy this simple code:
// Get recipe number from button
let recipeID = msg.payload;

// Set up the web request
msg.headers = {'Content-Type': 'application/json'};
msg.payload = JSON.stringify({ id: recipeID });

return msg;

  1. Click "Done"

What this does: Takes your recipe number and packages it the way the camera expects.

4.3 Set Up the HTTP Request

  1. Double-click the HTTP Request node
  2. Set Method to "POST"
  3. Set URL to localhost:5001/pipeline/activate
  4. Name it "Change Recipe"
  5. Click "Done"
备注

Before version 18.92: use http://[CAMERA_IP]/edge/pipeline/activate Version 18.92 and later: use http://localhost:5001/pipeline/activate

4.4 Set Up the Response Monitor

  1. Double-click the Debug node
  2. Name it "Recipe Change Result"
  3. Click "Done"

Perfect! Your recipe switcher is ready to test.

Step 5: Test Your Recipe Switcher

5.1 Deploy and Try It

  1. Click the red "Deploy" button
  2. Click your inject button (Switch to Recipe 15)
  3. Watch the debug panel for the response

5.2 Check If It Worked

Success signs:

  • Debug shows "success": true
  • Camera interface shows new recipe name
  • No error messages in debug panel

If it worked: Congratulations! You just remotely switched recipes.

If not: Check the troubleshooting section below.

5.3 Add More Recipe Buttons

Want multiple recipes? Just add more inject nodes:

  • Recipe 10 button: Payload = "10", Name = "Switch to Recipe 10"
  • Recipe 23 button: Payload = "23", Name = "Switch to Recipe 23"
  • All connect to the same Function node

Step 6: Use from Other Devices

Now the fun part! Any device can change recipes by sending web requests to your camera.

6.1 From Any Web Browser

Type this in any browser on your network:

http://192.168.0.100:5001/pipeline/activate

备注

Replace with your camera's IP address.

6.2 From Command Line

Windows/Mac/Linux - change to recipe 15:

curl -X POST http://192.168.0.100:5001/pipeline/activate \
-H "Content-Type: application/json" \
-d '{"id": "15"}'

6.3 From PLCs and Other Systems

Most modern systems can send HTTP requests:

  • Siemens PLCs: Use HTTP client blocks
  • Allen-Bradley: Use HTTP instruction blocks
  • Python/C#/Java: Use standard HTTP libraries
  • Custom apps: Any programming language works

The request format is always the same:

  • Method: POST
  • URL: http://[CAMERA_IP]:5001/pipeline/activate
  • Body: {"id": "RECIPE_NUMBER"}

Step 7: Make It Even Better

7.1 Add Recipe Validation

Want to prevent switching to non-existent recipes? Modify your function:

let recipeID = msg.payload;
let validRecipes = ["10", "15", "20"]; // Your actual recipe IDs

if (!validRecipes.includes(recipeID)) {
msg.payload = "Invalid recipe: " + recipeID;
return null; // Don't send request
}

// Normal formatting continues...

7.2 Product Code Mapping

Want to use product names instead of numbers? Try this:

let productCodes = {
"BOLT_A": "10",
"BOLT_B": "15",
"SCREW_C": "20"
};

let recipeID = productCodes[msg.payload];
// Continue with formatting...

Now you can trigger with product names instead of numbers!

7.3 Response Processing

Want better success/error messages? Add another function after HTTP Request:

let response = JSON.parse(msg.payload);

if (response.success) {
msg.payload = "✓ Recipe changed successfully!";
} else {
msg.payload = "✗ Recipe change failed: " + response.error;
}

return msg;

Step 8: Quick Troubleshooting

Not working? Here are the most common fixes:

ProblemQuick Fix
"Recipe not found" errorDouble-check your recipe ID number in the URL
No response at allVerify camera IP address and network connection
"Parse error" messageCheck that Function node code is copied correctly
Recipe doesn't actually changeMake sure the recipe exists and is not corrupted

Still stuck? Check that your camera is online and accessible from Node-RED.

You Did It!

Congratulations! You now have remote recipe control of your OV10i camera. With just a few clicks, you built a system that can:

  • Switch recipes instantly from any device on your network
  • Integrate with existing systems like PLCs, tablets, or computers
  • Support multiple recipes with simple button clicks
  • Validate requests to prevent errors
  • Work with custom applications using standard web technology

What's Next?

Now that you have the basics working, you can:

Easy Next Steps

  • Add more recipe buttons for all your products
  • Test from different devices like tablets or phones
  • Create custom product mappings for easier operation

Advanced Ideas

  • Build operator dashboards with recipe selection buttons
  • Connect to barcode scanners for automatic recipe selection
  • Integrate with MES systems for production line coordination
  • Add logging to track which recipes are used when

Real-World Examples

Here's how others use HTTP recipe switching:

  • Food Packaging: Barcode scanner triggers recipe change for different package sizes
  • Automotive: PLC switches recipes based on part type coming down the line
  • Electronics: Operator tablet with recipe buttons for different circuit boards
  • Quality Control: Automatic recipe switching based on production schedule

The possibilities are endless - and it all starts with the simple system you just built!

🔗 See Also