以太坊ETH-智能合约开发-solidity源码分析-truffle进阶

2024-05-07 13:32

本文主要是介绍以太坊ETH-智能合约开发-solidity源码分析-truffle进阶,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

0. 背景

上一篇文章我们从合约编写、编译、部署、交互等几个方面介绍了truffle的大致用法。
本篇主要继续深入地介绍truffle的高级用法 + 合约源码分析

1. 将合约部署到测试网Ropsten

1.1 注册infura获取API-KEY

infura是基于ETH的chain公共API服务,为开发者提供链上数据查询、交易广播等功能。

1.2 准备助记词

可从Web钱包MetaMask 上进行创建并导出助记词
一个助记词可以对应多个网络环境的地址,请勿向助记词对应的地址转入主网的ETH,否则有一定的安全风险

1.3 安装 truffle-hdwallet-provider

由于需要将合约部署到测试网Ropsten,此过程需要部署者私钥进行签名再将数据进行广播,truffle-hdwallet-providertruffle上提供交易离线签名的模块
:必须在truffle框架的代码目录下安装,否则不生效

 ✘ wujinquan@wujinquandeMacBook-Pro  ~/workspace/eth/truffle/defi  npm install truffle-hdwallet-provider
npm WARN deprecated truffle-hdwallet-provider@1.0.17: WARNING: This package has been renamed to @truffle/hdwallet-provider.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142> websocket@1.0.29 install /Users/wujinquan/workspace/eth/truffle/defi/node_modules/web3-providers-ws/node_modules/websocket
> (node-gyp rebuild 2> builderror.log) || (exit 0)CXX(target) Release/obj.target/bufferutil/src/bufferutil.o> websocket@1.0.31 install /Users/wujinquan/workspace/eth/truffle/defi/node_modules/websocket
> (node-gyp rebuild 2> builderror.log) || (exit 0)CXX(target) Release/obj.target/bufferutil/src/bufferutil.oSOLINK_MODULE(target) Release/bufferutil.nodeCXX(target) Release/obj.target/validation/src/validation.oSOLINK_MODULE(target) Release/validation.node
npm WARN saveError ENOENT: no such file or directory, open '/Users/wujinquan/workspace/eth/truffle/defi/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/Users/wujinquan/workspace/eth/truffle/defi/package.json'
npm WARN defi No description
npm WARN defi No repository field.
npm WARN defi No README data
npm WARN defi No license field.+ truffle-hdwallet-provider@1.0.17
added 326 packages from 212 contributors and audited 20646 packages in 114.122s
found 2 vulnerabilities (1 low, 1 high)run `npm audit fix` to fix them, or `npm audit` for details╭────────────────────────────────────────────────────────────────╮│                                                                ││      New minor version of npm available! 6.13.4 → 6.14.2       ││   Changelog: https://github.com/npm/cli/releases/tag/v6.14.2   ││               Run npm install -g npm to update!                ││                                                                │╰────────────────────────────────────────────────────────────────╯wujinquan@wujinquandeMacBook-Pro  ~/workspace/eth/truffle/defi  ls
build             defi              node_modules      test
contracts         migrations        package-lock.json truffle-config.jswujinquan@wujinquandeMacBook-Pro  ~/workspace/eth/truffle/defi 
1.4 修改truffle配置

主要修改ropsten网络配置,使truffle能顺利与ropsten交互

/*** Use this file to configure your truffle project. It's seeded with some* common settings for different networks and features like migrations,* compilation and testing. Uncomment the ones you need or modify* them to suit your project as necessary.** More information about configuration can be found at:** truffleframework.com/docs/advanced/configuration** To deploy via Infura you'll need a wallet provider (like @truffle/hdwallet-provider)* to sign your transactions before they're sent to a remote public node. Infura accounts* are available for free at: infura.io/register.** You'll also need a mnemonic - the twelve word phrase the wallet uses to generate* public/private key pairs. If you're publishing your code to GitHub make sure you load this* phrase from a file you've .gitignored so it doesn't accidentally become public.**/const HDWalletProvider = require("truffle-hdwallet-provider");
// const infuraKey = "fj4jll3k.....";
//
// const fs = require('fs');
// const mnemonic = fs.readFileSync(".secret").toString().trim();
const mnemonic = "grant boat distance require trap pair theme together spray blush glory simple"
//0x843ACfB41E5c0F1E0587C5B765d897cCDeA8c4DDmodule.exports = {/*** Networks define how you connect to your ethereum client and let you set the* defaults web3 uses to send transactions. If you don't specify one truffle* will spin up a development blockchain for you on port 9545 when you* run `develop` or `test`. You can ask a truffle command to use a specific* network from the command line, e.g** $ truffle test --network <network-name>*/networks: {// Useful for testing. The `development` name is special - truffle uses it by default// if it's defined here and no other network is specified at the command line.// You should run a client (like ganache-cli, geth or parity) in a separate terminal// tab if you use this network and you must also set the `host`, `port` and `network_id`// options below to some value.//// development: {//  host: "127.0.0.1",     // Localhost (default: none)//  port: 8545,            // Standard Ethereum port (default: none)//  network_id: "*",       // Any network (default: none)// },// Another network with more advanced options...// advanced: {// port: 8777,             // Custom port// network_id: 1342,       // Custom network// gas: 8500000,           // Gas sent with each transaction (default: ~6700000)// gasPrice: 20000000000,  // 20 gwei (in wei) (default: 100 gwei)// from: <address>,        // Account to send txs from (default: accounts[0])// websockets: true        // Enable EventEmitter interface for web3 (default: false)// },// Useful for deploying to a public network.// NB: It's important to wrap the provider as a function.ropsten: {provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/5c93axxx`),//示例无效network_id: 3,       // Ropsten's idgas: 5500000,        // Ropsten has a lower block limit than mainnetconfirmations: 2,    // # of confs to wait between deployments. (default: 0)timeoutBlocks: 200,  // # of blocks before a deployment times out  (minimum/default: 50)skipDryRun: true     // Skip dry run before migrations? (default: false for public nets )}// Useful for private networks// private: {// provider: () => new HDWalletProvider(mnemonic, `https://network.io`),// network_id: 2111,   // This network is yours, in the cloud.// production: true    // Treats this network as if it was a public net. (default: false)// }},// Set default mocha options here, use special reporters etc.mocha: {// timeout: 100000},// Configure your compilerscompilers: {solc: {// version: "0.5.1",    // Fetch exact version from solc-bin (default: truffle's version)// docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)// settings: {          // See the solidity docs for advice about optimization and evmVersion//  optimizer: {//    enabled: false,//    runs: 200//  },//  evmVersion: "byzantium"// }}}
}
1.5 部署至Ropsten

执行truffle migrate --network ropsten --reset 即可部署至Ropsten
如需要重新编译所有合约,可执行truffle migrate --network ropsten --reset --compile-all

 wujinquan@wujinquandeMacBook-Pro  ~/workspace/eth/truffle/defi  truffle migrate --network ropsten --resetCompiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.Starting migrations...
======================
> Network name:    'ropsten'
> Network id:      3
> Block gas limit: 0x7a121d1_initial_migration.js
======================Replacing 'Migrations'----------------------> transaction hash:    0x349ca58d8ed2176265efc58bf232878d930c71436a9b39796062489a638de396> Blocks: 2            Seconds: 92> contract address:    0x619DB4dda0cd2b3fF6351F52828Af5Cc44E6cA55> block number:        7531302> block timestamp:     1584376631> account:             0x843ACfB41E5c0F1E0587C5B765d897cCDeA8c4DD> balance:             0.47030684> gas used:            164175> gas price:           20 gwei> value sent:          0 ETH> total cost:          0.0032835 ETHPausing for 2 confirmations...------------------------------> confirmation number: 1 (block: 7531303)> confirmation number: 3 (block: 7531305)> Saving migration to chain.> Saving artifacts-------------------------------------> Total cost:           0.0032835 ETH2_deploy_contracts.js
=====================Replacing 'DeFi'----------------> transaction hash:    0x4be50b4e7a560080de6587078f937a553f29ac7b04ccd2e6b3802dc75dc8fe61> Blocks: 1            Seconds: 63> contract address:    0xB378420cde84c7A73EecfAeE2fC91ED364F45E9F> block number:        7531309> block timestamp:     1584376852> account:             0x843ACfB41E5c0F1E0587C5B765d897cCDeA8c4DD> balance:             0.4474762> gas used:            1099191> gas price:           20 gwei> value sent:          0 ETH> total cost:          0.02198382 ETHPausing for 2 confirmations...------------------------------> confirmation number: 1 (block: 7531310)> confirmation number: 2 (block: 7531311)> Saving migration to chain.> Saving artifacts-------------------------------------> Total cost:          0.02198382 ETHSummary
=======
> Total deployments:   2
> Final cost:          0.02526732 ETHwujinquan@wujinquandeMacBook-Pro  ~/workspace/eth/truffle/defi 
1.6 从区块浏览器上查看已部署的合约

从log输出可见DeFi合约地址为0xB378420cde84c7A73EecfAeE2fC91ED364F45E9F

2. 合约源码分析

项目源码可见Github仓库,主要分析DeFi.sol,过程以下代码中的详细中英文注释

pragma solidity >=0.4.25 <0.7.0;contract Token{mapping (address => uint256) balances;string  public name;string  public symbol;uint8   public decimals;uint256 public totalSupply;mapping (address => mapping (address => uint256)) allowed;//ERC20 Token Standard: https://eips.ethereum.org/EIPS/eip-20constructor() public { name = "Token";                                         	// Set the name symbol = "TK";                                              // Set the symbol decimals = 18;                                              // Amount of decimals for display purposes
//		totalSupply = 1000000000000000000000;                       // Not set total supply	}//Returns the account balance of another account with address _owner.function balanceOf(address _owner) public view returns (uint256 balance) {return balances[_owner];	}/* Transfers _value amount of tokens to address _to, and MUST fire the Transfer event. The function SHOULD throw if the message caller’s account balance does not have enough tokens to spend.Note Transfers of 0 values MUST be treated as normal transfers and fire the Transfer event.*/function transfer(address _to, uint256 _value) public returns (bool success) {require(_value > 0 );                                      // Check if token's value to be send > 0require(balances[msg.sender] >= _value);                   // Check if the sender has enough tokenrequire(balances[_to] + _value > balances[_to]);           // Check for overflows											balances[msg.sender] -= _value;                            // Subtract token from the senderbalances[_to] += _value;                                   // Add the same amount to the receiver                      emit Transfer(msg.sender, _to, _value); 				   // Notify anyone listening that this transaction happen.return true;      }/* The transferFrom method is used for a withdraw workflow, allowing contracts to transfer tokens on your behalf. This can be used for example to allow a contract to transfer tokens on your behalf and/or to charge fees in sub-currencies. The function SHOULD throw unless the _from account has deliberately authorized the sender of the message via some mechanism.Note Transfers of 0 values MUST be treated as normal transfers and fire the Transfer event.*/function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {require(balances[_from] >= _value);                 // Check if the sender has enough tokenrequire(balances[_to] + _value >= balances[_to]);   // Check for overflowsrequire(_value <= allowed[_from][msg.sender]);      // Check allowancebalances[_from] -= _value;                          // Subtract from the senderbalances[_to] += _value;                            // Add the same amount to the receiverallowed[_from][msg.sender] -= _value;emit Transfer(_from, _to, _value);return true;}/* Allows _spender to withdraw from your account multiple times, up to the _value amount. If this function is called again it overwrites the current allowance with _value.NOTE: To prevent attack vectors like the one described here and discussed here, clients SHOULD make sure to create user interfaces in such a way that they set the allowance first to 0 before setting it to another value for the same spender. THOUGH The contract itself shouldn’t enforce it, to allow backwards compatibility with contracts deployed before */function approve(address _spender, uint256 _value) public returns (bool success) {require(balances[msg.sender] >= _value);allowed[msg.sender][_spender] = _value;emit Approval(msg.sender, _spender, _value);return true;}//Returns the amount which _spender is still allowed to withdraw from _owner.function allowance(address _owner, address _spender) public view returns (uint256 remaining) {return allowed[_owner][_spender];}//The event for tranfer and approveevent Transfer(address indexed _from, address indexed _to, uint256 _value);event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}contract DeFi is Token{ //声明owner,暂时没作用address public owner ;//声明 用户-抵押ETH数量 mappingmapping (address => uint) pledgeETHAmount;//声明 抵押/赎回时的eventevent Pledge(address user, uint256 amount);event Redeem(address user, uint256 amount);//构造函数,只在合约被部署的时候执行一次constructor() public {owner = msg.sender ;}//抵押功能function pledge() public payable returns(bool success){//ETH抵押金额必须大于0require(msg.value > 0, "Not enough ETH to pledge.");//抵押操作// 1. 1:1贷出ERC20 TokenToken.balances[msg.sender] += msg.value;// 2. 写入抵押信息map,记录用户抵押ETH的数量:单位weipledgeETHAmount[msg.sender] += msg.value;// 3. 更新Token总量Token.totalSupply += msg.value;//记录抵押事件emit Pledge(msg.sender,msg.value);return true;}//赎回功能function redeem(uint256 value) public returns(bool success){//要求赎回ETH的数量必须 <= Token余额require(value <= Token.balances[msg.sender],"Not enough ETH to redeem.");//赎回操作// 1. 在合约转出ETH到用户地址之前将待发金额清零,更新用户Token余额和Token总量,来防止重入(re-entrancy)攻击Token.balances[msg.sender] -= value;Token.totalSupply -=  value;// 2. 从合约里转ETH到对应用户msg.sender.transfer(value);//记录赎回事件emit Redeem(msg.sender,value);return true;}
}

3. 与合约交互

在项目目录中执行truffle console --network ropsten连接ropsten并进入console模式

3.0 定义常用的抽象合约对象
truffle(ropsten)> let defi = await DeFi.deployed()  //合约对象定义为defi
undefined
truffle(ropsten)> let contractaddr = await defi.address 合约地址定义为contractaddr
undefined
truffle(ropsten)>
3.1 调用合约抵押ETH贷出ERC20代币TK

可见区块浏览器https://ropsten.etherscan.io/tx/0x6dcb3790976b0d3a6f0715739a3c771f192f39b3f1d2995a88f718d6df30c6d9

truffle(ropsten)> defi.pledge.sendTransaction({from:accounts[0],value:101}) //指定sender和抵押ETH数量,回显需要一点时间
{tx: '0x6dcb3790976b0d3a6f0715739a3c771f192f39b3f1d2995a88f718d6df30c6d9',receipt: {blockHash: '0x15b79d45581d83e7f5aaa40a9fac51c13d1824f188869207948c050fc4ded8ae',blockNumber: 7531333,contractAddress: null,cumulativeGasUsed: 85311,from: '0x843acfb41e5c0f1e0587c5b765d897ccdea8c4dd',gasUsed: 85311,logs: [ [Object] ],logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000200000000000000000000000000000000000040000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',status: true,to: '0xb378420cde84c7a73eecfaee2fc91ed364f45e9f',transactionHash: '0x6dcb3790976b0d3a6f0715739a3c771f192f39b3f1d2995a88f718d6df30c6d9',transactionIndex: 0,rawLogs: [ [Object] ]},logs: [{address: '0xB378420cde84c7A73EecfAeE2fC91ED364F45E9F',blockHash: '0x15b79d45581d83e7f5aaa40a9fac51c13d1824f188869207948c050fc4ded8ae',blockNumber: 7531333,logIndex: 0,removed: false,transactionHash: '0x6dcb3790976b0d3a6f0715739a3c771f192f39b3f1d2995a88f718d6df30c6d9',transactionIndex: 0,id: 'log_818726e7',event: 'Pledge',args: [Result]}]
}
truffle(ropsten)>
3.2 查询合约余额和用户的Token余额是否达到预期
truffle(ropsten)> web3.eth.getBalance(contractaddr) //合约的ETH余额
'101'
truffle(ropsten)> defi.balanceOf(accounts[0]) //用户的Token余额
BN {negative: 0,words: [ 101, <1 empty item> ],length: 1,red: null
}
truffle(ropsten)>
3.3 调用合约归还ERC20代币TK,赎回ETH

可见区块浏览器https://ropsten.etherscan.io/tx/0xa720d3da5eda30b9a816e68aaf41ddde0a536c2307734317f6b15243fb9b1829

truffle(ropsten)> defi.redeem.sendTransaction(99,{from:accounts[0]})  //归还99`TK`,1比1 赎回99`wei``ETH`
Error: Invalid JSON RPC response: ""at Object.InvalidResponse (/Users/wujinquan/workspace/eth/truffle/defi/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/gnidan/src/work/truffle/node_modules/web3/node_modules/web3-core-helpers/src/errors.js:42:1)at t.InvalidResponse [as onreadystatechange] (/Users/wujinquan/workspace/eth/truffle/defi/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/gnidan/src/work/truffle/node_modules/web3/node_modules/web3-providers-http/src/index.js:92:1)at t._a [as dispatchEvent] (/Users/wujinquan/workspace/eth/truffle/defi/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/gnidan/src/work/truffle/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:27:61)at t.dispatchEvent [as _setReadyState] (/Users/wujinquan/workspace/eth/truffle/defi/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/gnidan/src/work/truffle/node_modules/xhr2-cookies/dist/xml-http-request.js:208:1)at t._setReadyState [as _onHttpRequestError] (/Users/wujinquan/workspace/eth/truffle/defi/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/gnidan/src/work/truffle/node_modules/xhr2-cookies/dist/xml-http-request.js:349:1)at ClientRequest._onHttpRequestError (/Users/wujinquan/workspace/eth/truffle/defi/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/gnidan/src/work/truffle/node_modules/xhr2-cookies/dist/xml-http-request.js:252:47)at ClientRequest.emit (events.js:305:20)at ClientRequest.EventEmitter.emit (domain.js:483:12)at TLSSocket.socketErrorListener (_http_client.js:423:9)at TLSSocket.emit (events.js:305:20)at TLSSocket.EventEmitter.emit (domain.js:483:12)at emitErrorNT (internal/streams/destroy.js:84:8)at processTicksAndRejections (internal/process/task_queues.js:84:21)
{tx: '0xa720d3da5eda30b9a816e68aaf41ddde0a536c2307734317f6b15243fb9b1829',receipt: {blockHash: '0x0a08ef737e0729f31a2bd428eb50273833f669ebfc95b622cdf405c67996ceef',blockNumber: 7531341,contractAddress: null,cumulativeGasUsed: 756933,from: '0x843acfb41e5c0f1e0587c5b765d897ccdea8c4dd',gasUsed: 43116,logs: [ [Object] ],logsBloom: '0x00000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000040000000000000000000000000000000040000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000',status: true,to: '0xb378420cde84c7a73eecfaee2fc91ed364f45e9f',transactionHash: '0xa720d3da5eda30b9a816e68aaf41ddde0a536c2307734317f6b15243fb9b1829',transactionIndex: 1,rawLogs: [ [Object] ]},logs: [{address: '0xB378420cde84c7A73EecfAeE2fC91ED364F45E9F',blockHash: '0x0a08ef737e0729f31a2bd428eb50273833f669ebfc95b622cdf405c67996ceef',blockNumber: 7531341,logIndex: 1,removed: false,transactionHash: '0xa720d3da5eda30b9a816e68aaf41ddde0a536c2307734317f6b15243fb9b1829',transactionIndex: 1,id: 'log_2be7cb64',event: 'Redeem',args: [Result]}]
}
truffle(ropsten)>
3.4 查询赎回后合约余额和用户的Token余额是否达到预期
truffle(ropsten)> web3.eth.getBalance(contractaddr) //合约的ETH余额
'2'
truffle(ropsten)> defi.balanceOf(accounts[0]) //用户的Token余额
BN { negative: 0, words: [ 2, <1 empty item> ], length: 1, red: null }
truffle(ropsten)>

4.其它部署调试工具

对于开发者而言,可使用可视化工具Remix进行合约调试、部署
同一例子,详细参考以太坊ETH-智能合约开发-Remix使用

这篇关于以太坊ETH-智能合约开发-solidity源码分析-truffle进阶的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/967483

相关文章

Spring Security 从入门到进阶系列教程

Spring Security 入门系列 《保护 Web 应用的安全》 《Spring-Security-入门(一):登录与退出》 《Spring-Security-入门(二):基于数据库验证》 《Spring-Security-入门(三):密码加密》 《Spring-Security-入门(四):自定义-Filter》 《Spring-Security-入门(五):在 Sprin

这15个Vue指令,让你的项目开发爽到爆

1. V-Hotkey 仓库地址: github.com/Dafrok/v-ho… Demo: 戳这里 https://dafrok.github.io/v-hotkey 安装: npm install --save v-hotkey 这个指令可以给组件绑定一个或多个快捷键。你想要通过按下 Escape 键后隐藏某个组件,按住 Control 和回车键再显示它吗?小菜一碟: <template

Hadoop企业开发案例调优场景

需求 (1)需求:从1G数据中,统计每个单词出现次数。服务器3台,每台配置4G内存,4核CPU,4线程。 (2)需求分析: 1G / 128m = 8个MapTask;1个ReduceTask;1个mrAppMaster 平均每个节点运行10个 / 3台 ≈ 3个任务(4    3    3) HDFS参数调优 (1)修改:hadoop-env.sh export HDFS_NAMENOD

Java进阶13讲__第12讲_1/2

多线程、线程池 1.  线程概念 1.1  什么是线程 1.2  线程的好处 2.   创建线程的三种方式 注意事项 2.1  继承Thread类 2.1.1 认识  2.1.2  编码实现  package cn.hdc.oop10.Thread;import org.slf4j.Logger;import org.slf4j.LoggerFactory

性能分析之MySQL索引实战案例

文章目录 一、前言二、准备三、MySQL索引优化四、MySQL 索引知识回顾五、总结 一、前言 在上一讲性能工具之 JProfiler 简单登录案例分析实战中已经发现SQL没有建立索引问题,本文将一起从代码层去分析为什么没有建立索引? 开源ERP项目地址:https://gitee.com/jishenghua/JSH_ERP 二、准备 打开IDEA找到登录请求资源路径位置

嵌入式QT开发:构建高效智能的嵌入式系统

摘要: 本文深入探讨了嵌入式 QT 相关的各个方面。从 QT 框架的基础架构和核心概念出发,详细阐述了其在嵌入式环境中的优势与特点。文中分析了嵌入式 QT 的开发环境搭建过程,包括交叉编译工具链的配置等关键步骤。进一步探讨了嵌入式 QT 的界面设计与开发,涵盖了从基本控件的使用到复杂界面布局的构建。同时也深入研究了信号与槽机制在嵌入式系统中的应用,以及嵌入式 QT 与硬件设备的交互,包括输入输出设

OpenHarmony鸿蒙开发( Beta5.0)无感配网详解

1、简介 无感配网是指在设备联网过程中无需输入热点相关账号信息,即可快速实现设备配网,是一种兼顾高效性、可靠性和安全性的配网方式。 2、配网原理 2.1 通信原理 手机和智能设备之间的信息传递,利用特有的NAN协议实现。利用手机和智能设备之间的WiFi 感知订阅、发布能力,实现了数字管家应用和设备之间的发现。在完成设备间的认证和响应后,即可发送相关配网数据。同时还支持与常规Sof

JAVA智听未来一站式有声阅读平台听书系统小程序源码

智听未来,一站式有声阅读平台听书系统 🌟&nbsp;开篇:遇见未来,从“智听”开始 在这个快节奏的时代,你是否渴望在忙碌的间隙,找到一片属于自己的宁静角落?是否梦想着能随时随地,沉浸在知识的海洋,或是故事的奇幻世界里?今天,就让我带你一起探索“智听未来”——这一站式有声阅读平台听书系统,它正悄悄改变着我们的阅读方式,让未来触手可及! 📚&nbsp;第一站:海量资源,应有尽有 走进“智听

活用c4d官方开发文档查询代码

当你问AI助手比如豆包,如何用python禁止掉xpresso标签时候,它会提示到 这时候要用到两个东西。https://developers.maxon.net/论坛搜索和开发文档 比如这里我就在官方找到正确的id描述 然后我就把参数标签换过来

让树莓派智能语音助手实现定时提醒功能

最初的时候是想直接在rasa 的chatbot上实现,因为rasa本身是带有remindschedule模块的。不过经过一番折腾后,忽然发现,chatbot上实现的定时,语音助手不一定会有响应。因为,我目前语音助手的代码设置了长时间无应答会结束对话,这样一来,chatbot定时提醒的触发就不会被语音助手获悉。那怎么让语音助手也具有定时提醒功能呢? 我最后选择的方法是用threading.Time