mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-03-12 21:44:21 +00:00
Compare commits
3 Commits
feat/uniq_
...
feat/pr_bu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d3c28dcf5d | ||
|
|
6d70e62c1a | ||
|
|
dce4882226 |
81
.github/workflows/pr-build-env.yml
vendored
Normal file
81
.github/workflows/pr-build-env.yml
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
name: PR build with env
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
env:
|
||||
description: 'The environment to build for'
|
||||
required: true
|
||||
type: string
|
||||
is_esp32:
|
||||
description: 'Whether the build is for ESP32 based firmware'
|
||||
required: false
|
||||
type: boolean
|
||||
default: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out code from repo
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Cache Python dependencies
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.cache/pip
|
||||
key: ${{ runner.os }}-pip-${{ hashFiles('platformio.ini') }}
|
||||
|
||||
- name: Cache PlatformIO dependencies
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.pio/libdeps
|
||||
key: ${{ runner.os }}-pio-${{ hashFiles('platformio.ini') }}
|
||||
|
||||
- name: Set up Python 3.9
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: 3.9
|
||||
|
||||
- name: Inject secrets into ini file
|
||||
run: |
|
||||
sed -i 's/NO_AMS2MQTT_PRICE_KEY/AMS2MQTT_PRICE_KEY="${{secrets.AMS2MQTT_PRICE_KEY}}"/g' platformio.ini
|
||||
sed -i 's/NO_AMS2MQTT_PRICE_AUTHENTICATION/AMS2MQTT_PRICE_AUTHENTICATION="${{secrets.AMS2MQTT_PRICE_AUTHENTICATION}}"/g' platformio.ini
|
||||
sed -i 's/NO_AMS2MQTT_SC_KEY/AMS2MQTT_SC_KEY=\\"${{secrets.AMS2MQTT_SC_KEY}}\\"/g' platformio.ini
|
||||
sed -i 's/NO_ENERGY_SPEEDOMETER_USER/ENERGY_SPEEDOMETER_USER=\\"${{secrets.ENERGY_SPEEDOMETER_USER}}\\"/g' platformio.ini
|
||||
sed -i 's/NO_ENERGY_SPEEDOMETER_PASS/ENERGY_SPEEDOMETER_PASS=\\"${{secrets.ENERGY_SPEEDOMETER_PASS}}\\"/g' platformio.ini
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -U platformio css_html_js_minify
|
||||
|
||||
- name: Set up node
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '19.x'
|
||||
|
||||
- name: Build with node
|
||||
run: |
|
||||
cd lib/SvelteUi/app
|
||||
npm ci
|
||||
npm run build
|
||||
cd -
|
||||
env:
|
||||
CI: false
|
||||
|
||||
- name: PlatformIO lib install
|
||||
run: pio lib install
|
||||
|
||||
- name: Build firmware
|
||||
run: pio run -e ${{ inputs.env }}
|
||||
|
||||
- name: Create zip file
|
||||
run: /bin/sh scripts/${{ inputs.env }}/mkzip.sh
|
||||
|
||||
- name: Upload zip as artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ inputs.env }}
|
||||
path: ${{ inputs.env }}.zip
|
||||
retention-days: 7
|
||||
110
.github/workflows/pull-request.yml
vendored
Normal file
110
.github/workflows/pull-request.yml
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
name: Pull Request build
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
|
||||
jobs:
|
||||
build-esp32s2:
|
||||
uses: ./.github/workflows/pr-build-env.yml
|
||||
secrets: inherit
|
||||
with:
|
||||
env: esp32s2
|
||||
is_esp32: true
|
||||
|
||||
build-esp32s3:
|
||||
uses: ./.github/workflows/pr-build-env.yml
|
||||
secrets: inherit
|
||||
with:
|
||||
env: esp32s3
|
||||
is_esp32: true
|
||||
|
||||
build-esp32c3:
|
||||
uses: ./.github/workflows/pr-build-env.yml
|
||||
secrets: inherit
|
||||
with:
|
||||
env: esp32c3
|
||||
is_esp32: true
|
||||
|
||||
build-esp32:
|
||||
uses: ./.github/workflows/pr-build-env.yml
|
||||
secrets: inherit
|
||||
with:
|
||||
env: esp32
|
||||
is_esp32: true
|
||||
|
||||
build-esp32solo:
|
||||
uses: ./.github/workflows/pr-build-env.yml
|
||||
secrets: inherit
|
||||
with:
|
||||
env: esp32solo
|
||||
is_esp32: true
|
||||
|
||||
build-esp8266:
|
||||
uses: ./.github/workflows/pr-build-env.yml
|
||||
secrets: inherit
|
||||
with:
|
||||
env: esp8266
|
||||
is_esp32: false
|
||||
|
||||
comment:
|
||||
needs:
|
||||
- build-esp32s2
|
||||
- build-esp32s3
|
||||
- build-esp32c3
|
||||
- build-esp32
|
||||
- build-esp32solo
|
||||
- build-esp8266
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
pull-requests: write
|
||||
steps:
|
||||
- name: Post PR comment with download links
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const { owner, repo } = context.repo;
|
||||
const prNumber = context.payload.pull_request.number;
|
||||
const runId = context.runId;
|
||||
const runUrl = `https://github.com/${owner}/${repo}/actions/runs/${runId}`;
|
||||
|
||||
// Get the commit SHA (short version)
|
||||
const sha = context.payload.pull_request.head.sha;
|
||||
const shortSha = sha.substring(0, 7);
|
||||
|
||||
// Fetch the list of artifacts for this run via the API
|
||||
const artifactsResp = await github.rest.actions.listWorkflowRunArtifacts({ owner, repo, run_id: runId });
|
||||
const artifacts = artifactsResp.data.artifacts;
|
||||
|
||||
const envs = ['esp32s2', 'esp32s3', 'esp32c3', 'esp32', 'esp32solo', 'esp8266'];
|
||||
const lines = envs.map(env => {
|
||||
const artifact = artifacts.find(a => a.name === env);
|
||||
if (artifact) {
|
||||
// The artifact download page URL - directly navigable in the browser
|
||||
const artifactUrl = `${runUrl}#artifacts-${env}`;
|
||||
return `- **${env}**: [Download ${env}.zip](https://github.com/${owner}/${repo}/actions/runs/${runId}/artifacts/${artifact.id})`;
|
||||
}
|
||||
return `- **${env}**: ⚠️ artifact not found`;
|
||||
});
|
||||
|
||||
const body = [
|
||||
'## 🔧 PR Build Artifacts',
|
||||
'',
|
||||
`**Version**: \`${shortSha}\``,
|
||||
'',
|
||||
'All environments built successfully. Download the zip files:',
|
||||
'',
|
||||
...lines,
|
||||
'',
|
||||
`> Artifacts expire after 7 days. [View workflow run](${runUrl})`,
|
||||
].join('\n');
|
||||
|
||||
// Find and delete any previous bot comment to keep the PR clean
|
||||
const comments = await github.rest.issues.listComments({ owner, repo, issue_number: prNumber });
|
||||
for (const comment of comments.data) {
|
||||
if (comment.user.type === 'Bot' && comment.body.includes('PR Build Artifacts')) {
|
||||
await github.rest.issues.deleteComment({ owner, repo, comment_id: comment.id });
|
||||
}
|
||||
}
|
||||
|
||||
await github.rest.issues.createComment({ owner, repo, issue_number: prNumber, body });
|
||||
@@ -381,8 +381,6 @@ public:
|
||||
bool isZmartChargeConfigChanged();
|
||||
void ackZmartChargeConfig();
|
||||
|
||||
uint32_t getChipId();
|
||||
void getUniqueName(char* buffer, size_t length);
|
||||
|
||||
void clear();
|
||||
|
||||
|
||||
@@ -124,12 +124,16 @@ void AmsConfiguration::clearNetworkConfig(NetworkConfig& config) {
|
||||
memset(config.ssid, 0, 32);
|
||||
memset(config.psk, 0, 64);
|
||||
clearNetworkConfigIp(config);
|
||||
getUniqueName(config.hostname, 32);
|
||||
|
||||
uint16_t chipId;
|
||||
#if defined(ESP32)
|
||||
chipId = ( ESP.getEfuseMac() >> 32 ) % 0xFFFFFFFF;
|
||||
config.power = 195;
|
||||
#else
|
||||
chipId = ESP.getChipId();
|
||||
config.power = 205;
|
||||
#endif
|
||||
strcpy(config.hostname, (String("ams-") + String(chipId, HEX)).c_str());
|
||||
config.mdns = true;
|
||||
config.sleep = 0xFF;
|
||||
config.use11b = 1;
|
||||
@@ -979,23 +983,6 @@ void AmsConfiguration::setUiLanguageChanged() {
|
||||
uiLanguageChanged = true;
|
||||
}
|
||||
|
||||
uint32_t AmsConfiguration::getChipId() {
|
||||
uint32_t chipId;
|
||||
#if defined(ESP32)
|
||||
for(int i=0; i<17; i=i+8) {
|
||||
chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i;
|
||||
}
|
||||
#else
|
||||
chipId = ESP.getChipId();
|
||||
#endif
|
||||
return chipId;
|
||||
}
|
||||
|
||||
void AmsConfiguration::getUniqueName(char* buffer, size_t length) {
|
||||
uint32_t chipId = getChipId();
|
||||
snprintf(buffer, length, "ams-%06x", chipId);
|
||||
}
|
||||
|
||||
void AmsConfiguration::clear() {
|
||||
EEPROM.begin(EEPROM_SIZE);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"version": "%s",
|
||||
"chip": "%s",
|
||||
"chipId": "%06x",
|
||||
"chipId": "%s",
|
||||
"cpu": %d,
|
||||
"mac": "%s",
|
||||
"apmac": "%s",
|
||||
|
||||
@@ -306,14 +306,22 @@ void AmsWebServer::sysinfoJson() {
|
||||
|
||||
SystemConfig sys;
|
||||
config->getSystemConfig(sys);
|
||||
|
||||
char hostname[32];
|
||||
|
||||
uint32_t chipId;
|
||||
#if defined(ESP32)
|
||||
chipId = ( ESP.getEfuseMac() >> 32 ) % 0xFFFFFFFF;
|
||||
#else
|
||||
chipId = ESP.getChipId();
|
||||
#endif
|
||||
String chipIdStr = String(chipId, HEX);
|
||||
|
||||
String hostname;
|
||||
if(sys.userConfigured) {
|
||||
NetworkConfig networkConfig;
|
||||
config->getNetworkConfig(networkConfig);
|
||||
strncpy(hostname, networkConfig.hostname, 32);
|
||||
hostname = String(networkConfig.hostname);
|
||||
} else {
|
||||
config->getUniqueName(hostname, 32);
|
||||
hostname = "ams-"+chipIdStr;
|
||||
}
|
||||
|
||||
IPAddress localIp;
|
||||
@@ -413,7 +421,7 @@ void AmsWebServer::sysinfoJson() {
|
||||
#elif defined(ESP8266)
|
||||
"esp8266",
|
||||
#endif
|
||||
config->getChipId(),
|
||||
chipIdStr.c_str(),
|
||||
cpu_freq,
|
||||
macStr,
|
||||
apMacStr,
|
||||
@@ -421,7 +429,7 @@ void AmsWebServer::sysinfoJson() {
|
||||
sys.vendorConfigured ? "true" : "false",
|
||||
sys.userConfigured ? "true" : "false",
|
||||
sys.dataCollectionConsent,
|
||||
hostname,
|
||||
hostname.c_str(),
|
||||
performRestart ? "true" : "false",
|
||||
updater->getProgress() > 0.0 && upinfo.errorCode == 0 ? "true" : "false",
|
||||
#if defined(ESP8266)
|
||||
|
||||
@@ -901,7 +901,13 @@ void handleEnergySpeedometer() {
|
||||
if(sysConfig.energyspeedometer == 7) {
|
||||
if(!meterState.getMeterId().isEmpty()) {
|
||||
if(energySpeedometer == NULL) {
|
||||
config.getUniqueName(energySpeedometerConfig.clientId, 32);
|
||||
uint16_t chipId;
|
||||
#if defined(ESP32)
|
||||
chipId = ( ESP.getEfuseMac() >> 32 ) % 0xFFFFFFFF;
|
||||
#else
|
||||
chipId = ESP.getChipId();
|
||||
#endif
|
||||
strcpy(energySpeedometerConfig.clientId, (String("ams") + String(chipId, HEX)).c_str());
|
||||
energySpeedometer = new JsonMqttHandler(energySpeedometerConfig, &Debug, (char*) commonBuffer, &hw, &ds, &updater);
|
||||
energySpeedometer->setCaVerification(false);
|
||||
}
|
||||
@@ -1454,29 +1460,17 @@ void toggleSetupMode() {
|
||||
#else
|
||||
WiFi.beginSmartConfig();
|
||||
#endif
|
||||
|
||||
char ssid[32];
|
||||
if(sysConfig.vendorConfigured) {
|
||||
// Use the standard SSID if the vendor has configured the device
|
||||
strcpy_P(ssid, PSTR("AMS2MQTT"));
|
||||
} else {
|
||||
// If not vendor configured, use a unique SSID to avoid conflicts if multiple devices are in setup mode at the same time
|
||||
config.getUniqueName(ssid, 32);
|
||||
}
|
||||
uint8_t debugLevel = RemoteDebug::INFO;
|
||||
#if defined(DEBUG_MODE)
|
||||
debugLevel = RemoteDebug::VERBOSE;
|
||||
#endif
|
||||
WiFi.softAP(ssid);
|
||||
Debug.setSerialEnabled(true);
|
||||
Debug.begin(F("192.168.4.1"), 23, debugLevel);
|
||||
debugI_P(PSTR("SSID: %s"), ssid);
|
||||
WiFi.softAP(PSTR("AMS2MQTT"));
|
||||
|
||||
if(dnsServer == NULL) {
|
||||
dnsServer = new DNSServer();
|
||||
}
|
||||
dnsServer->setErrorReplyCode(DNSReplyCode::NoError);
|
||||
dnsServer->start(53, PSTR("*"), WiFi.softAPIP());
|
||||
#if defined(DEBUG_MODE)
|
||||
Debug.setSerialEnabled(true);
|
||||
Debug.begin(F("192.168.4.1"), 23, RemoteDebug::VERBOSE);
|
||||
#endif
|
||||
setupMode = true;
|
||||
|
||||
hw.setBootSuccessful(false);
|
||||
|
||||
Reference in New Issue
Block a user