sys_http.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "httpclient.h"
  2. #include "string.h"
  3. #include "stdio.h"
  4. #include "main.h"
  5. #include "sys_http.h"
  6. #include "log.h"
  7. #include "gd32_flash.h"
  8. #include "netconf.h"
  9. //http配置标志位
  10. uint8_t load_http_config=0;
  11. //get请求 http://gpu.ringzle.com:8082/iot/transmit/getTransmitConfig/DT8pd3ac6h 端口8082
  12. //目前为此处去控制http一次性读入数据大小,应为该处为读入函数
  13. void http_getDemo(void)
  14. {
  15. int datalen;
  16. int ret;
  17. while(dhcp_done != 1)
  18. {
  19. vTaskDelay(100);
  20. }
  21. char *device_config=pvPortMalloc(10);
  22. memset(device_config, 0,10);
  23. read_data_from_flash(device_config);
  24. if((strstr(device_config,"tcp_config")) == NULL)
  25. {
  26. // LogPrint(LOG_INFO,__FILE__,__FUNCTION__,__LINE__,"HTTP Get config");
  27. char *http_data=pvPortMalloc(10 * 1024); // 接收数据上限为25K
  28. char *http=pvPortMalloc(50);
  29. sprintf(http,"/iot/transmit/getTransmitConfig/%s",gatewayId);
  30. ret = http_clientGet("gpu.ringzle.com", http, 8082, 0, http_data, &datalen);
  31. if(ret==200) //获取成功
  32. {
  33. // LogPrint(LOG_INFO,__FILE__,__FUNCTION__,__LINE__,"HTTP Get config success");
  34. // sprintf(http_data,"tcp_config");
  35. save_config_params(http_data);
  36. load_http_config=1;
  37. }
  38. vPortFree(http_data);
  39. vPortFree(http);
  40. }
  41. vPortFree(device_config);
  42. }
  43. char *postData = "{\"bandwidth\":250,\"codeRate\":4700}";
  44. uint8_t postResult[512];
  45. //POST请求 http://gpu.ringzle.com/iot/test/httpTest 端口号8082
  46. void http_postDemo(void)
  47. {
  48. int datalen, ret;
  49. memset(postResult, 0, sizeof(postResult));
  50. // ret = http_clientPost("gpu.ringzle.com", "/iot/test/httpTest", 8082, 0, http_data, 5837, postResult, &datalen);
  51. ret = http_clientPost("gpu.ringzle.com", "/iot/test/httpTest", 8082, 0, (uint8_t *)postData, strlen(postData), postResult, &datalen);
  52. HTTP_PRINTF("%s", (char *)postResult);
  53. HTTP_PRINTF("\r\n ret=%d datalen=%d\r\n", ret, datalen);
  54. }
  55. /*
  56. *********************************************************************************************************
  57. * 函 数 名: int get_http_config(void)
  58. * 功能说明: 获取http配置的相关参数
  59. * 形 参:无
  60. * 返 回 值: 返回http是否配置 0:没有配置过,1:配置过
  61. *********************************************************************************************************
  62. */
  63. int get_http_config(void)
  64. {
  65. return load_http_config;
  66. }