app.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <web_crawler.h>
  2. #include <alloc/web_crawler_alloc.h>
  3. /**
  4. * @brief Entry point for the WebCrawler application.
  5. * @param p Input parameter - unused
  6. * @return 0 to indicate success, -1 on failure
  7. */
  8. int32_t web_crawler_app(void *p)
  9. {
  10. UNUSED(p);
  11. app_instance = web_crawler_app_alloc();
  12. if (!app_instance)
  13. {
  14. FURI_LOG_E(TAG, "Failed to allocate WebCrawlerApp");
  15. return -1;
  16. }
  17. if (!flipper_http_ping())
  18. {
  19. FURI_LOG_E(TAG, "Failed to ping the device");
  20. return -1;
  21. }
  22. // Edit from Derek Jamison
  23. if (app_instance->text_input_ssid != NULL && app_instance->text_input_password != NULL)
  24. {
  25. // Try to wait for pong response.
  26. uint8_t counter = 10;
  27. while (fhttp.state == INACTIVE && --counter > 0)
  28. {
  29. FURI_LOG_D(TAG, "Waiting for PONG");
  30. furi_delay_ms(100);
  31. }
  32. if (counter == 0)
  33. {
  34. DialogsApp *dialogs = furi_record_open(RECORD_DIALOGS);
  35. DialogMessage *message = dialog_message_alloc();
  36. dialog_message_set_header(
  37. message, "[FlipperHTTP Error]", 64, 0, AlignCenter, AlignTop);
  38. dialog_message_set_text(
  39. message,
  40. "Ensure your WiFi Developer\nBoard or Pico W is connected\nand the latest FlipperHTTP\nfirmware is installed.",
  41. 0,
  42. 63,
  43. AlignLeft,
  44. AlignBottom);
  45. dialog_message_show(dialogs, message);
  46. dialog_message_free(message);
  47. furi_record_close(RECORD_DIALOGS);
  48. }
  49. }
  50. // Run the application
  51. view_dispatcher_run(app_instance->view_dispatcher);
  52. // Free resources after the application loop ends
  53. web_crawler_app_free(app_instance);
  54. return 0;
  55. }