Loading [MathJax]/jax/input/TeX/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >发送json对象并重置时esp8266崩溃

发送json对象并重置时esp8266崩溃
EN

Stack Overflow用户
提问于 2021-08-08 04:24:48
回答 1查看 334关注 0票数 0

你好,我正在尝试发送一个使用arduinoJson库的JSON对象。当它是一个小的json对象时,一切都很好,但当它变得更大时,esp8266就会崩溃并重置。我可以在调试时看到它创建了json对象,但是当它使用ajax POST方法发送它时,它就崩溃了。在图片中,您可以看到串行监视器,还可以看到创建了json对象,但是当它发送该对象时,esp8266会崩溃并重新启动Serial debug。我相信问题与这行代码Possible problem有关

esp8266上的代码如下所示。

代码语言:javascript
运行
AI代码解释
复制
#include <Arduino.h>
#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
#include <Hash.h>
#include <WiFiClientSecure.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <FS.h>
#include <Wire.h>
#include "max6675.h"
#include <UniversalTelegramBot.h>
#define BOTtoken "1863133375:AAFE3m83AFQYaRjqOas2Kr-DB5fhbONCZ80"
#define CHAT_ID "-599306428"


const int thermoCS = D8;
const int thermoCLK = D5;
int x = 0;
int r[] = {1,1,1,1,1};
int lk;

int TEMP1[121];
int TEMP2[121];
int TEMP3[121];
int TEMP4[121];
int TEMP5[121];

MAX6675 thermocouple_TEMP1(thermoCLK, thermoCS, D7);
MAX6675 thermocouple_TEMP2(thermoCLK, thermoCS, D6);
MAX6675 thermocouple_TEMP3(thermoCLK, thermoCS, D2);
MAX6675 thermocouple_TEMP4(thermoCLK, thermoCS, D1);
MAX6675 thermocouple_TEMP5(thermoCLK, thermoCS, D0); // esp8266 skal bruge D0, hvor ESP32 skal bruge 0
WiFiClientSecure client;
X509List cert(TELEGRAM_CERTIFICATE_ROOT);
WiFiClientSecure secure_client;
UniversalTelegramBot bot(BOTtoken, secure_client);
// Replace with your network credentials
const char* ssid = "Telenor646209_EXT";
const char* password = "";

// Create AsyncWebServer object on port 80
AsyncWebServer server(80);

String temp5() {
  float f = abs(thermocouple_TEMP5.readCelsius()) ;
    return String(f);
    client.stop();
}
String temp4() {
  float d = abs(thermocouple_TEMP4.readCelsius()) ;
    return String(d);
    client.stop();
}
String temp3() {
  float s = abs(thermocouple_TEMP3.readCelsius()) ;
    return String(s);
    client.stop();
}
String temp2() {
  float a = abs(thermocouple_TEMP2.readCelsius());
    return String(a);
    client.stop();
}

String temp1() {
  float m = abs(thermocouple_TEMP1.readCelsius());
    return String(m);
    client.stop();
}
String TEMP() {
  String Json;
  StaticJsonDocument<54000> doc;
JsonArray Temp1 = doc.createNestedArray("Temp1");
JsonArray Temp2 = doc.createNestedArray("Temp2");
JsonArray Temp3 = doc.createNestedArray("Temp3");
JsonArray Temp4 = doc.createNestedArray("Temp4");
JsonArray Temp5 = doc.createNestedArray("Temp5");
  for (int i = 0; i <= x-1; i++) {
  Temp1.add(TEMP1[i]);
  Temp2.add(TEMP2[i]);
  Temp3.add(TEMP3[i]);
  Temp4.add(TEMP4[i]);
  Temp5.add(TEMP5[i]);
  }
  serializeJson(doc, Json);
  Serial.println(Json);
    return Json;
    client.stop();
}


void setup(){
  // Serial port for debugging purposes
  configTime(0, 0, "pool.ntp.org");      // get UTC time via NTP
  secure_client.setTrustAnchors(&cert); // Add root certificate for api.telegram.org
  Serial.begin(9600);
  // Initialize SPIFFS
  if(!SPIFFS.begin()){
    //Serial.println("An Error has occurred while mounting SPIFFS");
    return;
  }
  // Connect to Wi-Fi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    //Serial.println("Connecting to WiFi..");
  }
  Serial.println(WiFi.localIP());
  // Print ESP32 Local IP Address
  // Route for root / web page
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send(SPIFFS, "/index.html");
  });
  server.on("/temp1", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/plain", temp1().c_str());
  });
  server.on("/temp2", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/plain", temp2().c_str());
  });
  server.on("/temp3", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/plain", temp3().c_str());
  });
  server.on("/temp4", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/plain", temp4().c_str());
  });
  server.on("/temp5", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/plain", temp5().c_str());
  });
  server.on("/TEMP", HTTP_POST, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/plain", TEMP().c_str());
  });

  // Start server
  server.begin();
    //bot.sendMessage(CHAT_ID, "EPS8266_fyr starter", "");
}
 
void loop(){
 TEMP1[x] = x;//abs(thermocouple_TEMP1.readCelsius()); 
 TEMP2[x] = x;//abs(thermocouple_TEMP2.readCelsius());
 TEMP3[x] = x;//abs(thermocouple_TEMP3.readCelsius());
 TEMP4[x] = x;//abs(thermocouple_TEMP4.readCelsius());
 TEMP5[x] = x;//abs(thermocouple_TEMP5.readCelsius());
  //Serial.print("TEMP værdier:");
  //Serial.print(x);
  //Serial.print(" TEMP1: ");
  Serial.print(TEMP1[x]);
  //Serial.print(" TEMP2: ");
  Serial.print(TEMP2[x]);
 //Serial.print(" TEMP3: ");
  Serial.print(TEMP3[x]);
  //Serial.print(" TEMP4: ");
  Serial.print(TEMP4[x]);
  //Serial.print(" TEMP5: ");
  Serial.println(TEMP5[x]);
  x += 1;
  if(TEMP1[x] >= 35){
  //bot.sendMessage(CHAT_ID, "Nedsfaldsrørs temperatur er over 35°C", "");
 }
  if(x == 120){  
    x=119;
    if(x>118) {
      for (int antal = 0; antal <= 118; antal++){
         TEMP1[antal] = TEMP1[antal+1]; 
         TEMP2[antal] = TEMP2[antal+1];
         TEMP3[antal] = TEMP3[antal+1];
         TEMP4[antal] = TEMP4[antal+1]; 
         TEMP5[antal] = TEMP5[antal+1];  
      }
  
    }
  }
  delay(1000);
}

我的代码的最后一部分是HTML/JAVASCRIPT,它看起来像这样。

代码语言:javascript
运行
AI代码解释
复制
<!DOCTYPE HTML><html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <script src="https://code.highcharts.com/highcharts.js"></script>
  <style>
    h2 {
      font-family: Arial;
      font-size: 2.5rem;
      text-align: center;

    }
  </style>
</head>
<body>
  <h2>DASH BOARD</h2>
  <div id="chart-temperature" class="container"></div>
  <p id="demo"></p>
  <p id="demo2"></p>
</body>
<script>
var Json;
var d = new Date();
var h = d.getHours();
var c = d.getMinutes();
var chartT = new Highcharts.Chart({
  chart:{
    renderTo : 'chart-temperature',
    type: 'line',
    zoomType: 'x',
    panning: true,
    panKey: 'shift'
  },
  tooltip: {
  dateTimeLabelFormats: {
    millisecond: "%A, %b %e, %H:%M"
  }
},
  title: { text: 'temperature' },
  series: [{
    name: 'TEMP1',
    showInLegend: true,
    connectNulls: true,
    data: [],
    color: '#FF0000'
  }, {
     name: 'TEMP2',
     connectNulls: true,
    data:[],
    color: '#4572A7'
  },
  {
     name: 'TEMP3',
     connectNulls: true,
    data:[],
    color: '#000000'
  },
  {
     name: 'TEMP4',
     connectNulls: true,
    data:[],
    color: '#0000FF'
  },
  {
     name: 'TEMP5',
     connectNulls: true,
    data:[],
    color: '#6600FF'
  }],

  plotOptions: {
    line: { animation: false,
      dataLabels: { enabled: true }

    },
  },
  xAxis: { type: 'datetime',
    dateTimeLabelFormats: { second: '%H:%M:%S' },
    min: Date.UTC(0,0,0,h,c-120,0), tickInterval: 30*60*1000, max: Date.UTC(0,0,0,h,c,0)
  },
  yAxis: {
    title: { text: 'Temperature (Celsius)' },
    //title: { text: 'Temperature (Fahrenheit)' }
  },
  credits: { enabled: false }
});
Highcharts.setOptions({
    time: {
        useUTC: true
    }
});
function loadall(){
  var m;
  var tid;
  var y1;
  var y;
  var just;
    var xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      if(chartT.series[0].data.length == 0){
        y1 = this.responseText;
        y = JSON.parse(y1);
        just = y.Temp1.length;
      for (let i = 0; i < just; i++) {
         tid = Date.UTC(0,0,0,h,(c-i),0);
            chartT.series[0].addPoint([tid, y.Temp1[just-i-1]], true, false, false);
            chartT.series[1].addPoint([tid, y.Temp2[just-i-1]], true, false, false);
            chartT.series[2].addPoint([tid, y.Temp3[just-i-1]], true, false, false);
            chartT.series[3].addPoint([tid, y.Temp4[just-i-1]], true, false, false);
            chartT.series[4].addPoint([tid, y.Temp5[just-i-1]], true, false, false);
          }
           }
            }
             }
    xhttp.open("POST", "TEMP", true);
    xhttp.send();
  }
  function Load(serie,sensor,tid){
    var xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function() {
        var y = parseFloat(this.responseText);
    if (this.readyState == 4 && this.status == 200) {
            chartT.series[serie].addPoint([tid, y], true, true, false);
          }
           }
    xhttp.open("GET", sensor, false);
    xhttp.send();
  }
  loadall();
  setInterval(function(){
    d = new Date();
    h = d.getHours();
    c = d.getMinutes();
    chartT.xAxis[0].update({
        max: Date.UTC(0,0,0,h,c,0),
        min: Date.UTC(0,0,0,h,c-120,0)
    });
    Load(0,"temp1",Date.UTC(0,0,0,h,c,0));
    Load(1,"temp2",Date.UTC(0,0,0,h,c,0));
    Load(2,"temp3",Date.UTC(0,0,0,h,c,0));
    Load(3,"temp4",Date.UTC(0,0,0,h,c,0));
    Load(4,"temp5",Date.UTC(0,0,0,h,c,0));
  }, 60000);

</script>
</html>
EN

回答 1

Stack Overflow用户

发布于 2021-08-10 07:12:05

我找到了导致重置的问题,是ESP8266的看门狗在6秒后重置了它。这意味着我必须重写我的程序,要么将json数组保存在SPIFFS中,要么将其分成更小的部分发送。

修复方法是升级到ESP32,因为ESP8266速度不够快

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68700739

复制
相关文章
httpclient post发送json数组并解决json乱码问题
业务: 客户端发送json数据,服务端进行解析 client发送json格式: {"data":[{"name":"1;,a","id_no":"222,a","cellphone":"123141a","abode_detail":"213,a","emp_add":"werew3a","app_no":"111111111111a","create_time":"11a"},{"name":"张三","id_no":"null","cellphone":"null","abode_detai
shengjk1
2018/10/24
4.3K0
HttpClient 发送get请求并返回Json数据
一、以百度百科接口为例 http://baike.baidu.com/api/openapi/BaikeLemmaCardApi?scope=103&format=json&appid=379020&
week
2018/08/24
3.3K0
HttpClient 发送get请求并返回Json数据
mysql中保存并操作json对象
"At the end of the day, we can endure much more than we think we can.—— Frida Kahlo"
小闫同学啊
2020/03/25
14.4K0
json转对象时一直报错
问题:json格式的请求体经controller控制器会自动转换成对象格式。可是的json请求的key和对应的类的字段是一模一样的,发送请求总是显示400错误,估计是请求体错误。可是并没有发现错误啊,请求的字段都是复制的,百思不得其解,只能逐个定位,一步一步的找错。
全栈程序员站长
2022/08/05
5640
json数据发送时浏览器提示“保存”解决
数据以json形式发送的时候,部分浏览器不能直接解析,而是提示是否保存,nodejs的express应用中可以通过如下代码解决该问题: router.get('/', function (req, res, next) { ... res.type("html"); ... }); 这样浏览器就不会再提示保存了。。。
用户1141560
2017/12/26
1.3K0
python中将字符串转为json对象并
string =" {   "status": "error",   "messages": ["Could not find resource or operation 'BZK1.MapServer' on the system."],   "code": 404
py3study
2020/01/09
1.3K0
HttpClient 发送Json
import com.fasterxml.jackson.databind.ObjectMapper; import msxf.model.People; import msxf.until.ImpalaJdbc; import msxf.until.NowDate; import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.http.HttpS
shengjk1
2018/10/24
2.3K0
java json数组转json对象_json对象数组
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
全栈程序员站长
2022/09/30
10.5K0
java json数组转json对象_json对象数组
Springboot实战:发送邮件/重置密码业务
忘记密码并通过邮件重置密码是一个常见的业务需求,在开发我的个人小项目过程中,也需要用到这个业务,今天就给大家带来一个业务实战。
Rude3Knife的公众号
2019/08/07
1.6K0
python中将字符串转为json对象并取值
"messages": ["Could not find resource or operation 'BZK1.MapServer' on the system."],
用户7886150
2021/01/16
2.3K0
[Springboot]发送邮件、重置密码业务实战
忘记密码并通过邮件重置密码是一个常见的业务需求,在开发我的个人小项目过程中,也需要用到这个业务,今天就给大家带来一个业务实战。
蛮三刀酱
2019/03/26
7890
postman 发送json请求
Tags: 工具 Archives QR Code
简单、
2018/07/17
1.5K0
json对象转map对象_json map
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/172454.html原文链接:https://javaforall.cn
全栈程序员站长
2022/09/23
2.7K0
JSON对象
目录 JSON JSON语法 JSON静态函数 访问JSON对象 JSON JSON是一种数据交换格式 JSON语法 数据都是有名称/值对组成 名称和值对是由冒号分隔 JSON静态函数 parse 将JSON格式的字符串转换为JSON对象 var str = '{"hvge":1,"hv":2}' console.log(JSON.parse(str)) stringify 将JSON对象转化为字符串 var oJson = { "hvge": 1, "hv":
星辉
2019/01/15
1.4K0
JSON 对象
key 必须是字符串,value 可以是合法的 JSON 数据类型(字符串, 数字, 对象, 数组, 布尔值或 null)。
陈不成i
2021/07/13
1.2K0
前端json字符串转json对象_list对象转json
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
全栈程序员站长
2022/11/10
4.4K0
.net c# json转对象 对象转json
.net和java中操作json不像php那么轻巧方便,之前我使用.net json转对象,需要创建一个json实体类,繁琐至极。
高久峰
2023/07/02
5530
Java技术点-json转对象,对象转json
Fastjson 是一个 Java 库,可以将 Java 对象转换为 JSON 格式,当然它也可以将 JSON 字符串转换为 Java 对象。
用户9006224
2022/12/21
3.3K0
jackson简单使用,对象转json,json转对象,json转list
添加jackson依赖: // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.8.2' // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind
Ryan-Miao
2018/03/13
8K0
点击加载更多

相似问题

当试图发送Json对象时,应用程序崩溃

11

如何在ESP8266 MicroPython崩溃后重置main.py?

44

Esp8266无限重置

10

发送空格和点时Json崩溃

10

发送json对象后应用程序崩溃

20
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档