import 'dotenv/config'; // Configuration const BASE_URL = 'http://www.acinfinityserver.com'; const USER_AGENT = 'ACController/1.9.7 (com.acinfinity.humiture; build:533; iOS 18.5.0) Alamofire/5.10.2'; // Helper to check credentials if (!process.env.AC_EMAIL || !process.env.AC_PASSWORD) { console.error('Error: AC_EMAIL and AC_PASSWORD must be set in .env file'); process.exit(1); } /** * Login to AC Infinity API * @returns {Promise} userId (token) */ async function login() { console.log('Attempting login...'); const params = new URLSearchParams(); params.append('appEmail', process.env.AC_EMAIL); params.append('appPasswordl', process.env.AC_PASSWORD); // Note: appPasswordl with 'l' try { const response = await fetch(`${BASE_URL}/api/user/appUserLogin`, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': USER_AGENT }, body: params }); const data = await response.json(); if (data.code === 200) { console.log('Login successful!'); return data.data.appId; // This is the token } else { throw new Error(`Login failed: ${data.msg || 'Unknown error'} (Code: ${data.code})`); } } catch (error) { console.error('Login error:', error.message); throw error; } } /** * Get All Devices * @param {string} token * @returns {Promise} device list */ async function getDeviceList(token) { console.log('Fetching device list...'); const params = new URLSearchParams(); params.append('userId', token); try { const response = await fetch(`${BASE_URL}/api/user/devInfoListAll`, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': USER_AGENT, 'token': token, 'phoneType': '1', 'appVersion': '1.9.7' }, body: params }); const data = await response.json(); if (data.code === 200) { const devices = data.data || []; console.log(`Found ${devices.length} devices.`); return devices; } else { throw new Error(`Get device list failed: ${data.msg} (Code: ${data.code})`); } } catch (error) { console.error('Get device list error:', error.message); throw error; } } /** * Get Device Mode Settings * @param {string} token * @param {string} devId * @param {number} port */ async function getDeviceModeSettings(token, devId, port = 1) { console.log(`Fetching settings for device ${devId}, port ${port}...`); const params = new URLSearchParams(); params.append('devId', devId); params.append('port', port.toString()); try { const response = await fetch(`${BASE_URL}/api/dev/getdevModeSettingList`, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': USER_AGENT, 'token': token, 'phoneType': '1', 'appVersion': '1.9.7', 'minversion': '3.5' }, body: params }); const data = await response.json(); if (data.code === 200) { console.log('Settings retrieved successfully.'); return data.data; } else { // 403 or other errors might happen console.warn(`Get settings warning: ${data.msg} (Code: ${data.code})`); return null; } } catch (error) { console.error('Get settings error:', error.message); return null; } } // Main execution async function main() { try { // 1. Login const token = await login(); // 2. Get Devices const devices = await getDeviceList(token); if (devices.length === 0) { console.log("No devices found on this account."); return; } // 3. Inspect first device const firstDevice = devices[0]; console.log('\n--- First Device Details ---'); console.log(`Name: ${firstDevice.devName}`); console.log(`ID: ${firstDevice.devId}`); console.log(`Mac Address: ${firstDevice.devMacAddr || 'N/A'}`); console.log(`Type: ${firstDevice.devType}`); console.log(`WiFi SSID: ${firstDevice.wifiName || 'N/A'}`); console.log(`Firmware: ${firstDevice.firmwareVersion || 'N/A'}`); console.log(`Hardware: ${firstDevice.hardwareVersion || 'N/A'}`); // 4. Get Settings for first device const settings = await getDeviceModeSettings( token, firstDevice.devId, firstDevice.externalPort || 1 ); if (settings) { console.log('\n--- Device Settings (First Port) ---'); const tempC = settings.temperature ? settings.temperature / 100 : 'N/A'; const tempF = settings.temperatureF ? settings.temperatureF / 100 : 'N/A'; const hum = settings.humidity ? settings.humidity / 100 : 'N/A'; const vpd = settings.vpdnums ? settings.vpdnums / 100 : 'N/A'; console.log(`Temperature: ${tempC}°C / ${tempF}°F`); console.log(`Humidity: ${hum}%`); console.log(`VPD: ${vpd} kPa`); console.log(`Current Fan Speed: ${settings.speak}/10`); console.log(`On Speed: ${settings.onSpead}/10`); console.log(`Off Speed: ${settings.offSpead}/10`); console.log('-----------------------------------'); } } catch (error) { console.error('Script failed:', error); } } main();