自己编译NodeMCU固件 & 提交数据到服务器
2017-05-27 10:26
323 查看
自己编译NodeMCU固件
之前这篇文章nodeMCU使用小记里用到的固件是比较老的固件,不带http模块,所以无法实现http的post请求。所以……在云构建固件没法用的情况下,还得自己编译固件啊。。编译固件的系统环境是ubuntu-14.04.4-desktop-i386,步骤如下:
先安装编译工具链esp-open-sdk:
sudo apt-get install make unrar-free autoconf automake libtool gcc g++ gperf flex bison texinfo gawk ncurses-dev libexpat-dev python-dev python python-serial sed git unzip bash help2man wget bzip2 git clone --recursive https://github.com/pfalcon/esp-open-sdk.git cd esp-open-sdk make 最后按照提示把环境变量加到/etc/profile里,再source一下
再克隆nodemcu项目进行编译:
git clone https://github.com/nodemcu/nodemcu-firmware.git cd nodemcu-firmware (有很多modules是可选项,可在app/include/user_modules.h将其注释掉) (波特率在app/include/user_config.h里定义) (Integer build选项也在app/include/user_config.h里定义) (在app/include/user_version.h里自定义个人签名) make
最后刷固件:
# 首选把自己加入对话群,不然没法访问串口 sudo adduser ph dialout # 把固件上载到nodemcu里 make flash #这里提示是512kb还是4m,自己选
到这里固件就刷好了,效果如图:
参考:
esp-open-sdk
物联网应用——从源代码为ESP8266创建NodeMCU
NodeMCU Build Options
ubuntu 将当前用户加入到串口所在组
NodeMCU提交数据到服务器
NodeMCU端init.lua:-- init.lua print(wifi.sta.getip()) print('Setting up WIFI...') wifi.setmode(wifi.STATION) wifi.sta.config('test', '11223344') wifi.sta.connect() -- 要想提交数据到远程服务器,首先得连上互联网啊2333 tmr.alarm(1, 1000, tmr.ALARM_AUTO, function() if wifi.sta.getip() == nil then print('Waiting for IP ...') else print('IP is ' .. wifi.sta.getip()) http.post('http://192.168.223.193/nodemcu_data_process.php', -- 服务器ip是192.168.223.193 'Content-Type: application/json\r\n', '{"name":"hello"}', function(code, data) if (code < 0) then print("HTTP request failed") else print(code, data) end end) tmr.stop(1) end end)
PHP服务端代码:
<?php $str = file_get_contents ( "php://input" ); $args = (json_decode ( $str )); $user_name = isset ( $args->name ) ? $args->name : null; $message = array ( "type" => 0, "name" => $user_name ); $json_string=json_encode($message); error_log($json_string,3,'/opt/lampp/logs/nodemcu.log'); echo $json_string; ?>
效果如图:
nodemcu端:
xampp端:
参考:
NodeMCU教程 http.post请求及服务端接收不到参数解决方案
项目部署到远程Linux服务器
相关文章推荐
- Multipart/form-data POST文件上传详解 理论 简单的HTTP POST 大家通过HTTP向服务器发送POST请求提交数据,都是通过form表单提交的,代码如下: <form me
- 自己动手编译NodeMCU固件
- 采用浏览器端操作减小服务器负担——数据批量录入一次提交
- 利用WebRequest来实现模拟浏览器通过Post方式向服务器提交数据
- dojo中客户端向服务器提交数据
- asp net中的服务器按钮方式提交数据
- 对象失去焦点时自己动提交数据
- 2003下从网页中把数据导出到excel时,碰到"Automation 服务器不能创建对象"的问题
- sencha touch 向服务器提交数据
- 用Form向服务器提交数据
- 每隔10秒,客户端向服务器提交一次数据
- C# 模拟post数据提交时 出现如下错误: System.Net.WebException: 远程服务器返回错误: (417) Expectation Failed 的解决办法
- Linux下程式开发2 变量数据类型的代码以及编译&运算符与表达式
- 使用Jquery实现可编辑的表格 并使用AJAX提交到服务器修改数据
- 用Jquery实现可编辑表格并用AJAX提交到服务器修改数据
- 20110215 学习记录2:表单中的get和post区别 & 使用 HttpWebRequest 向网站提交数据
- 利用WebRequest来实现模拟浏览器通过Post方式向服务器提交数据
- 使用Jquery实现可编辑的表格 并使用AJAX提交到服务器修改数据
- 如何不用服务器控件提交数据
- form有2中方法把数据提交给服务器-编码问题