Expresss+gulp+MongoDB搭建网站(四)--gulp详解

 上一节中,我们创建了一个任务,但这个任务啥也没干,这一节,我们来学习如何通过配置gulpfile.js文件来实现我们想要的各种功能。

一、常用API

1、task

 gulp.task(name [, deps, fn]) 用于创建任务

 其中,name 是task的名字,deps是可选项,就是这个task依赖的tasks(可以是个list),fn是task要执行的函数。

 现在,我们将gulp.task文件修改为:

var gulp = require("gulp");

gulp.task("pre_task1", function() {
	console.log("enter task1 !");
})

gulp.task("pre_task2", function() {
	console.log("enter task2 !");
})

gulp.task("cur_task", ["pre_task1", "pre_task2"], function(){
    console.log("enter current task!");
});

 在命令行执行gulp cur_task:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
/*模拟STM32设备向EMQ发送数据 */ const mqtt = require('mqtt'); const host = 'iot-06z00cad6kypevk.mqtt.iothub.aliyuncs.com' const port = '1883' const clientId = `iqfzjbFKlyh.js_node_one|securemode=2,signmethod=hmacsha256,timestamp=1685192902891|` const connectUrl = `mqtt://${host}:${port}` const client = mqtt.connect(connectUrl, { clientId, clean: true, connectTimeout: 4000, username: 'js_node_one&iqfzjbFKlyh', password: 'f4cf365e0ed0a68ef9eff1ce571f959a66b1bc9a9970174cd55203e94975b4d2', reconnectPeriod: 1000, }) var stm32_esp8266_obj = {}; var studentNo = "2020070230114";//替换你的学号 const subcribe_topic = `/ota/device/inform/iqfzjbFKlyh/js_node_one`; const publish_topic = `/ota/device/upgrade/iqfzjbFKlyh/js_node_one`; client.on('connect', () => {D:/users/deskttop/iot/sy4/iot_cloudesp8266_mqtt_expresss console.log('MQTT Connected') client.subscribe([subcribe_topic], () => { console.log(`Subscribe to topic '${subcribe_topic}'`) }); setInterval(()=>{ var chushuiliang1=Math.floor(Math.random() * 20)+1; var chushuiliang2=Math.floor(Math.random() * 40)+1; var jinshuiliang=chushuiliang1+chushuiliang2+Math.floor(Math.random() * 10)+1; var zhuodu2 = Math.floor(Math.random() * 20)+1; var zhuodu3 = Math.floor(Math.random() * 20)+1; var zhuodu1 = zhuodu2+zhuodu3+Math.floor(Math.random() * 5)+1; var publish_obj={ error:0, wendu1:Math.floor(Math.random() * 40), wendu2:Math.floor(Math.random() * 40), yulv1:Math.random().toFixed(4), yulv2:Math.random().toFixed(4), yewei:Math.random().toFixed(4), ph1:Math.floor(Math.random() * 13), ph2:Math.floor(Math.random() * 13), shui:[jinshuiliang,chushuiliang1,chushuiliang2], zhuodu:[zhuodu1,zhuodu2,zhuodu3] } client.publish(publish_topic, JSON.stringify(publish_obj), { qos: 0, retain: false }, (error) => { if (error) { console.error(error) } }) },5000); }) client.on('message', (topic, payload) => { console.log('Received Message:', topic, payload.toString()); stm32_esp8266_obj = JSON.parse(payload); // console.log(stm32_esp8266_obj); })
06-08

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值