#include <ESP32_FTPClient.h> #define B_LED_PIN 18 #define W_LED_PIN 16 #define Y_LED_PIN 5 #define R_LED_PIN 17 #define X_A_IN_PIN 34 #define Y_A_IN_PIN 35 #define Z_A_IN_PIN 36 #define SW_PIN 19 #define CY_MEAS_PIN 11 #define MOTOR_GET_PIN 14 #define MOTOR_WAIT_PIN 12 #define MOTOR_PULSE_PIN 13 #define SSID "" //ルータのID #define PASS "" //ルータのパスワード(ハッシュ化) #define NTP_SERVER "pool.ntp.org" //時間取得 NTPサーバ #define FTP_SERVER "10.0.1.119" #define FTP_USER "ftp_data" #define FTP_PASS "" #define FTP_DIR "acceleration" #define SENSOR_FILE_NAME "ftp_data" //センサからの取得データの格納ファイル名 #define SENSOR_NAME "Accelerometer" //センサの名前 #define MAX_DATA_SIZE 5000 #define SAMPS_DELAY 109 enum MotionStatus {STATE_ERROR = -1 , STATE_SETUP, STATE_WAIT, STATE_GET, STATE_SEND}; IPAddress local_IP(10,0,1,60); IPAddress gateway_IP(10,0,1,250); IPAddress subnet_Mask(255,255,255,0); ESP32_FTPClient ftp(FTP_SERVER, FTP_USER, FTP_PASS, 5000, 0); void connectWiFi() { Serial.println("OKOKOKOK"); if(!WiFi.config(local_IP, gateway_IP, subnet_Mask)) { delay(100); Serial.println("STA Failed to configure"); } delay(100); Serial.printf("Connenting to %s\n",SSID); WiFi.begin(SSID, PASS); wl_status_t state; while (true) { state = WiFi.status(); delay(1); if(state == WL_CONNECTED) { Serial.println("WiFi connected!!\n"); break; }else if(state == WL_NO_SHIELD) { Serial.println("Connecting WiFi"); WiFi.begin(SSID, PASS); }else if(state == WL_CONNECT_FAILED) { Serial.println("Disconnecting WiFi"); WiFi.disconnect(true); }else if(state == WL_DISCONNECTED) { Serial.println("WiFi discooected"); } delay(250); } } void syncTime() { configTime(9 * 3600L, 0, NTP_SERVER); } void setLED(enum MotionStatus state) { switch (state) { case STATE_ERROR: //digitalWrite(B_LED_PIN, HIGH); //digitalWrite(W_LED_PIN, HIGH); //digitalWrite(Y_LED_PIN, HIGH); digitalWrite(R_LED_PIN, LOW); break; case STATE_SETUP: digitalWrite(B_LED_PIN, LOW); digitalWrite(W_LED_PIN, LOW); digitalWrite(Y_LED_PIN, LOW); digitalWrite(R_LED_PIN, HIGH); break; case STATE_WAIT: digitalWrite(B_LED_PIN, HIGH); digitalWrite(W_LED_PIN, HIGH); digitalWrite(Y_LED_PIN, HIGH); digitalWrite(R_LED_PIN, HIGH); break; case STATE_GET: digitalWrite(B_LED_PIN, HIGH); digitalWrite(W_LED_PIN, LOW); digitalWrite(Y_LED_PIN, HIGH); digitalWrite(R_LED_PIN, HIGH); break; case STATE_SEND: digitalWrite(B_LED_PIN, LOW); digitalWrite(W_LED_PIN, HIGH); digitalWrite(Y_LED_PIN, HIGH); digitalWrite(R_LED_PIN, HIGH); break; } } /* * bool pulse_falled = false; * void motor_interrupt() { * pulse_falled = ture; * } * * bool pulseFalled() { * if (pulse_falled == true) { * pilse_falled = false; * return true; * } * return false; * } */ void setup() { // put your setup code here, to run once: Serial.begin(115200); pinMode(B_LED_PIN, OUTPUT); pinMode(W_LED_PIN, OUTPUT); pinMode(Y_LED_PIN, OUTPUT); pinMode(R_LED_PIN, OUTPUT); digitalWrite(B_LED_PIN, HIGH); digitalWrite(W_LED_PIN, HIGH); digitalWrite(Y_LED_PIN, HIGH); digitalWrite(R_LED_PIN, HIGH); pinMode(SW_PIN, INPUT_PULLUP); pinMode(CY_MEAS_PIN, OUTPUT); setLED(STATE_SETUP); connectWiFi(); syncTime(); pinMode(MOTOR_GET_PIN, INPUT); //attachInterrup(MOTOR_GET_PIN, motor_interrupt, FALLING); } int data_size; int zero_count; struct tm tm; uint8_t motor_out[MAX_DATA_SIZE]; //uint16_t xout[MAX_DATA_SIZE], yout[MAX_DATA_SIZE], zout{MAX_DATA_SIZE]; char* p_ftp_buf = new char[70]; char* file_name = new char[30]; const double offset = 1.65 / 3.3 * 4096; const double convert = 3.3 / 4096 /0.66; //float Xout[MAX_DATA_SIZE], Yout[MAX_DATA_SIZE], Zout[MAX_DATA_SIZE]; void loop() { // put your main code here, to run repeatedly: setLED(STATE_WAIT); while (digitalRead(MOTOR_GET_PIN) == HIGH); Serial.println("Accelerometer value measurement started."); setLED(STATE_GET); getLocalTime(&tm); uint16_t *xout, *yout, *zout; float *Xout, *Yout, *Zout; xout = (uint16_t *)malloc(sizeof(uint16_t) * MAX_DATA_SIZE); yout = (uint16_t *)malloc(sizeof(uint16_t) * MAX_DATA_SIZE); zout = (uint16_t *)malloc(sizeof(uint16_t) * MAX_DATA_SIZE); Xout = (float *)malloc(sizeof(float) * MAX_DATA_SIZE); Yout = (float *)malloc(sizeof(float) * MAX_DATA_SIZE); Zout = (float *)malloc(sizeof(float) * MAX_DATA_SIZE); for (data_size = 0; data_size < MAX_DATA_SIZE; data_size++) { motor_out[data_size] = (digitalRead(MOTOR_GET_PIN) == HIGH) ? 1 : 0; xout[data_size] = analogRead(X_A_IN_PIN); yout[data_size] = analogRead(Y_A_IN_PIN); zout[data_size] = analogRead(Z_A_IN_PIN); digitalWrite(CY_MEAS_PIN, LOW); delayMicroseconds(SAMPS_DELAY); digitalWrite(CY_MEAS_PIN, HIGH); delayMicroseconds(SAMPS_DELAY); } for (data_size = 0; data_size < MAX_DATA_SIZE; data_size++) { Xout[data_size] = (float)(9.8 * ((xout[data_size] - offset) * convert)); Yout[data_size] = (float)(9.8 * ((yout[data_size] - offset) * convert)); Zout[data_size] = (float)(9.8 * ((zout[data_size] - offset) * convert)); } Serial.println("Accelerometer value measurement completed. "); Serial.println("File transfer started. "); setLED(STATE_SEND); ftp.OpenConnection(); ftp.InitFile("Type I"); ftp.ChangeWorkDir(FTP_DIR); //sprintf(file_name, "%04d%02d%02d%02d%02d02d%_%s.csv", //tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, SENSOR_FILE_NAME); //ftp.NewFile(file_name); ftp.NewFile("data.csv"); sprintf(p_ftp_buf, "%s,%04d%02d%02d%02d%02d02d%,%d\n", SENSOR_NAME, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, data_size); ftp.Write(p_ftp_buf); for (data_size = 0; data_size < MAX_DATA_SIZE; data_size++) { sprintf(p_ftp_buf, "%d,%d,%f,%f,%f,\n", data_size, motor_out[data_size], Xout[data_size], Yout[data_size], Zout[data_size]); ftp.Write(p_ftp_buf); } ftp.CloseFile(); ftp.CloseConnection(); free(xout); free(yout); free(zout); free(Xout); free(Yout); free(Zout); for (data_size = 0; data_size < MAX_DATA_SIZE; data_size++) { if (motor_out[data_size] == 0) zero_count++; } Serial.printf("zero_count : %d\n", zero_count); zero_count = 0; Serial.println("File transfer completed.\n"); while (digitalRead(MOTOR_GET_PIN) == LOW); } コード
devkitcを使って加速度センサからのデータをWiFiを通して取得しようとしてます。
コンパイルエラーは出ないのですが、シリアルモニタではE(10582)がでます。
回答1件
あなたの回答
tips
プレビュー