csdn产品小助手 2016-01-26 09:19 采纳率: 0%
浏览 34

Arduino未写入文件

I'd like the arduino to write to a file whenever an ajax call is made. The ajax works, but it doesn't write to the file. All other code inside the ajax handler does execute.

void handle_ajax(){
int startUrlIndex= HTTP_req.indexOf("button");
int endUrlIndex = HTTP_req.indexOf(" HTTP");
String url = HTTP_req.substring(startUrlIndex, endUrlIndex);

int startButtonIndex = url.indexOf("device-") + 7;// 7 is length of device-, I really just want the number.
int endButtonIndex = url.indexOf("&");
String button = url.substring(startButtonIndex, endButtonIndex);

int startStateIndex = url.indexOf("state=") + 6; // 6 is length of state=, I really just want the number.
String state = url.substring(startStateIndex);

int device = button.toInt();
int newState = state.toInt();

dim_light(device, newState * 12);
write_config("", "text");
}

bool write_config(String line, String text){
configFile = SD.open("config.ini", FILE_WRITE);

if(configFile){
    configFile.write("Dipshit");
}
configFile.close();
Serial.println("Works.");
return true;
}
  • 写回答

2条回答 默认 最新

  • weixin_33728708 2016-04-03 14:17
    关注

    I don't see anything wrong with the code provided.

    Check the basics first:

    • SD card is either a standard SD card or a SDHC card.
    • SD card is formatted with a FAT16 or FAT32 file system.
    • The correct pin has been used for the CS pin in the SD.begin() command. This depends on the hardware used. http://www.arduino.cc/en/Reference/SDCardNotes
    • The SPI is wired up correctly (pins 11, 12, and 13 on most Arduino boards).
    • The hardware SS pin is set as an output (even if it isn't used as the CS pin).

    I know from past experience that these little Arduinos can run out of SRAM quite quickly when reading and writing to an SD card. The ReadWrite example program uses about 50% of the UNOs SRAM alone!!
    To test if this is your problem, run the SD card read/write example program (with the correct CS pin in the SD.begin() command). If this works then the problem is likely that you have run out of SRAM. Try using an Arduino MEGA 2560 instead which has 4x the amount of SRAM.

    Edit: The latest Arduino IDE (v1.6.8) actually calculates how much SRAM is used by global variables. It does not take into account local variables.

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料