Giter VIP home page Giter VIP logo

arduino-compat's People

Contributors

cpq avatar daadu avatar dimonomid avatar nliviu avatar qrpp avatar rojer avatar ruslanvaliullin avatar yaourdt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

arduino-compat's Issues

Arduino Compat starts before dependencies are initialized

I am specially impacted by the mgos spi lib as the arduino code in setup() sends comms before mgos_spi_create is fired.

[Jan 22 23:50:35.303] I (643) cpu_start: Pro cpu start user code
[Jan 22 23:50:35.310] I (327) cpu_start: Starting scheduler on PRO CPU.
[Jan 22 23:50:35.329] mgos_init2           blynk 1.0 (20180122-060206/master@878e023d+)
[Jan 22 23:50:35.335] mgos_init2           Mongoose OS 1.24 (20180122-023650/1.24@bd8e2958)
[Jan 22 23:50:35.341] mgos_init2           CPU: 160 MHz, RAM: 294644 total, 256260 free
[Jan 22 23:50:35.347] mgos_hal_freertos_pr ESP-IDF v3.0-rc1-r1
[Jan 22 23:50:35.352] mgos_hal_freertos_pr Boot partition: app_0; flash: 4M
[Jan 22 23:50:35.359] mgos_vfs_dev_open    esp32part ({"label": "fs_0", "subtype": 130}) -> 0x3ffc107c
[Jan 22 23:50:35.368] mgos_vfs_mount       Mount SPIFFS @ / (dev 0x3ffc107c, opts {"encr": false}) -> 0x3ffc0fc0
[Jan 22 23:50:35.491] mgos_vfs_mount       /: size 233681, used: 127006, free: 106675
[Jan 22 23:50:35.599] mgos_sys_config_init MAC: 30AEA435CE28
[Jan 22 23:50:35.605] mgos_sys_config_init WDT: 30 seconds
[Jan 22 23:50:35.610] mgos_deps_init       init adc...
[Jan 22 23:50:35.613] mgos_deps_init       init arduino_compat...
[Jan 22 23:50:35.619] setup                arduino.cpp::setup()
[Jan 22 23:50:40.624] setup                arduino.cpp::setup() delay
[Jan 22 23:50:40.630] MD_MAX72XX::begin()
[Jan 22 23:50:40.634] spiInit              Initing MAX72xx...
[Jan 22 23:50:40.640] spiInit              Using ESP32 SPI settings in mos.yml...
[Jan 22 23:50:40.647] SPI spiSend!
[Jan 22 23:50:40.651] spiInit              Initing MAX72xx...
[Jan 22 23:50:40.656] spiInit              Using ESP32 SPI settings in mos.yml...
[Jan 22 23:50:40.664] SPI spiSend!
[Jan 22 23:50:40.667] spiInit              Initing MAX72xx...
[Jan 22 23:50:40.673] spiInit              Using ESP32 SPI settings in mos.yml...
[Jan 22 23:50:40.680] SPI spiSend!
[Jan 22 23:50:40.684] spiInit              Initing MAX72xx...
[Jan 22 23:50:40.689] spiInit              Using ESP32 SPI settings in mos.yml...
[Jan 22 23:50:40.697] SPI spiSend!
[Jan 22 23:50:40.700] spiInit              Initing MAX72xx...
[Jan 22 23:50:40.706] spiInit              Using ESP32 SPI settings in mos.yml...
[Jan 22 23:50:40.713] SPI spiSend!
[Jan 22 23:50:40.717] spiInit              Initing MAX72xx...
[Jan 22 23:50:40.723] spiInit              Using ESP32 SPI settings in mos.yml...
[Jan 22 23:50:40.730] SPI spiSend!
[Jan 22 23:50:40.733] spiInit              Initing MAX72xx...
[Jan 22 23:50:40.739] spiInit              Using ESP32 SPI settings in mos.yml...
[Jan 22 23:50:40.747] SPI spiSend!
[Jan 22 23:50:40.750] spiInit              Initing MAX72xx...
[Jan 22 23:50:40.756] spiInit              Using ESP32 SPI settings in mos.yml...
[Jan 22 23:50:40.763] SPI spiSend!
[Jan 22 23:50:40.767] spiInit              Initing MAX72xx...
[Jan 22 23:50:40.772] spiInit              Using ESP32 SPI settings in mos.yml...
[Jan 22 23:50:40.780] SPI spiSend!
[Jan 22 23:50:40.783] spiInit              Initing MAX72xx...
[Jan 22 23:50:40.789] spiInit              Using ESP32 SPI settings in mos.yml...
[Jan 22 23:50:40.796] SPI spiSend!
[Jan 22 23:50:40.800] spiInit              Initing MAX72xx...
[Jan 22 23:50:40.805] spiInit              Using ESP32 SPI settings in mos.yml...
[Jan 22 23:50:40.813] SPI spiSend!
[Jan 22 23:50:40.816] spiInit              Initing MAX72xx...
[Jan 22 23:50:40.822] spiInit              Using ESP32 SPI settings in mos.yml...
[Jan 22 23:50:40.829] SPI spiSend!
[Jan 22 23:50:40.833] spiInit              Initing MAX72xx...
[Jan 22 23:50:40.839] spiInit              Using ESP32 SPI settings in mos.yml...
[Jan 22 23:50:40.846] SPI spiSend!
[Jan 22 23:50:40.849] spiInit              Initing MAX72xx...
[Jan 22 23:50:40.855] spiInit              Using ESP32 SPI settings in mos.yml...
[Jan 22 23:50:40.863] SPI spiSend!
[Jan 22 23:50:40.866] spiInit              Initing MAX72xx...
[Jan 22 23:50:40.872] spiInit              Using ESP32 SPI settings in mos.yml...
[Jan 22 23:50:40.879] mgos_deps_init       init onewire...
[Jan 22 23:50:40.882] mgos_deps_init       init arduino_onewire...
[Jan 22 23:50:40.886] mgos_deps_init       init arduino_dallas_temperature...
[Jan 22 23:50:40.891] mgos_deps_init       init spi...
[Jan 22 23:50:40.896] mgos_spi_create      SPI3 init ok (MISO: 19, MOSI: 23, SCLK: 18; CS0/1/2: 5/-1/-1; native? yes)
[Jan 22 23:50:40.907] mgos_deps_init       init arduino_spi...
[Jan 22 23:50:40.910] mgos_deps_init       init arduino_md_max72xx...
[Jan 22 23:50:40.915] mgos_deps_init       init arduino_md_parola...
[Jan 22 23:50:40.919] mgos_deps_init       init i2c...
[Jan 22 23:50:40.922] mgos_deps_init       init arduino_wire...
[Jan 22 23:50:40.925] mgos_deps_init       init blynk...
[Jan 22 23:50:40.930] mgos_deps_init       init ca_bundle...
[Jan 22 23:50:40.934] mgos_deps_init       init location...
[Jan 22 23:50:40.937] mgos_deps_init       init sntp...
[Jan 22 23:50:40.942] mgos_deps_init       init cron...
[Jan 22 23:50:40.945] mgos_deps_init       init jstore...
[Jan 22 23:50:40.948] mgos_deps_init       init crontab...
[Jan 22 23:50:40.954] find_mount_by_path   crontab.json -> /crontab.json pl 1 -> 1 0x3ffc0fc0
[Jan 22 23:50:40.968] mgos_vfs_open        crontab.json 0x0 0x1b6 => 0x3ffc0fc0 crontab.json -1 => -1 (refs 0)
[Jan 22 23:50:40.978] mgos_deps_init       init mjs...
[Jan 22 23:50:40.983] mgos_mjs_init        mJS memory stat: before init: 258172 after init: 256768
[Jan 22 23:50:40.992] mgos_deps_init       init pwm...
[Jan 22 23:50:40.995] mgos_deps_init       init rpc_common...
[Jan 22 23:50:41.000] mgos_deps_init       init rpc_service_config...
[Jan 22 23:50:41.007] mgos_deps_init       init rpc_service_fs...
[Jan 22 23:50:41.013] mgos_deps_init       init rpc_uart...
[Jan 22 23:50:41.019] mg_rpc_channel_uart  0x3ffb9d78 UART0
[Jan 22 23:50:41.025] mg_rpc_add_channel_i 0x3ffb9d78 '' UART
[Jan 22 23:50:41.030] mgos_deps_init       init wifi...
[Jan 22 23:50:41.035] mgos_wifi_setup      WiFi mode: AP
[Jan 22 23:50:41.040] esp32_wifi_set_mode  WiFi mode: AP

micros() behaves strangely after sntp finishes.

Code:

void beep(void *arg) {
  LOG(LL_INFO, ("mg_time: %lf", mg_time()));
  LOG(LL_INFO, ("micros: %lu", micros()));
  (void) arg;
}

enum mgos_app_init_result mgos_app_init(void) {
  mgos_set_timer(1000, true, beep, NULL);
  
  return MGOS_APP_INIT_SUCCESS;
}

Console before/after sntp:

[Sep  6 21:38:18.698] beep                 mg_time: 1.341552
[Sep  6 21:38:18.704] beep                 micros: 1346312
[Sep  6 21:38:19.698] beep                 mg_time: 2.341633
[Sep  6 21:38:19.704] beep                 micros: 2346268
[Sep  6 21:38:20.715] dhcp client start...
[Sep  6 21:38:20.716] mgos_net_on_change_c WiFi STA: connected
[Sep  6 21:38:21.588] ip:192.168.1.161,mask:255.255.255.0,gw:192.168.1.1
[Sep  6 21:38:21.594] mgos_net_on_change_c WiFi STA: ready, IP 192.168.1.161, GW 192.168.1.1, DNS 192.168.1.1
[Sep  6 21:38:21.697] beep                 mg_time: 4.340778
[Sep  6 21:38:21.702] beep                 micros: 4345307
[Sep  6 21:38:22.591] mgos_sntp_query      SNTP query to pool.ntp.org
[Sep  6 21:38:22.595] mongoose_poll        New heap free LWM: 44872
[Sep  6 21:38:22.606] mongoose_poll        New heap free LWM: 42744
[Sep  6 21:38:22.627] mongoose_poll        New heap free LWM: 42608
[Sep  6 21:38:22.697] beep                 mg_time: 5.341536
[Sep  6 21:38:22.701] beep                 micros: 5345951
[Sep  6 21:38:22.715] mgos_sntp_ev         SNTP reply from 192.111.144.114: time 1504759101.576770, local 5.358226, delta 1504759096.218544
[Sep  6 21:38:23.710] beep                 mg_time: 1504759102.560543
[Sep  6 21:38:23.714] beep                 micros: 4294967295
[Sep  6 21:38:24.709] beep                 mg_time: 1504759103.559169
[Sep  6 21:38:24.716] beep                 micros: 4294967295
[Sep  6 21:38:25.710] beep                 mg_time: 1504759104.559839
[Sep  6 21:38:25.715] beep                 micros: 4294967295
[Sep  6 21:38:26.709] beep                 mg_time: 1504759105.559733

After SNTP, micros() starts returning 4294967295 (2^32 - 1) for all calls.

micros() is based on mg_time() which returns a double and reports wall clock (it is not monotonic).

The Arduino docs say this about micros():

Returns the number of microseconds since the Arduino board began running the current program

Should mongoose's Arduino compat, then, use the boot-time (monotonic?) clock instead of the wall clock (sync'd with sntp)?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.